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 6d317f47c..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 /-! @@ -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" @@ -694,10 +696,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 +710,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..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 @@ -464,10 +466,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 +489,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 +518,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..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 diff --git a/Iris/Iris/Algebra/CMRA.lean b/Iris/Iris/Algebra/CMRA.lean index cf238df17..3bb281db3 100644 --- a/Iris/Iris/Algebra/CMRA.lean +++ b/Iris/Iris/Algebra/CMRA.lean @@ -7,10 +7,13 @@ module public import Iris.Algebra.OFE public import Iris.Algebra.Monoid +public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris open OFE @@ -215,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 @@ -282,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 := @@ -304,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 @@ -316,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 := @@ -523,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 := @@ -750,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). @@ -759,11 +762,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 - _ ≡{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₂ := @@ -773,7 +776,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) := @@ -971,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" @@ -1004,19 +1007,19 @@ end CMRA section rFunctor @[rocq_alias rFunctor] -class RFunctor (F : COFE.OFunctorPre) where +class RFunctor (F : COFE.OFunctorPre Nat) where [cmra [COFE α] [COFE β] : CMRA (F α β)] map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x + 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) extends (RFunctor F) where +class RFunctorContractive (F : COFE.OFunctorPre Nat) extends (RFunctor F) where map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) @@ -1024,16 +1027,16 @@ attribute [reducible, instance] RFunctor.cmra @[rocq_alias rFunctor_to_oFunctor] -instance RFunctor.toOFunctor [R : RFunctor F] : COFE.OFunctor 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 +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 map_comp f g f' g' x := RFunctor.map_comp f g f' g' x @[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,19 +1044,19 @@ end rFunctor section urFunctor @[rocq_alias urFunctor] -class URFunctor (F : COFE.OFunctorPre) where +class URFunctor (F : COFE.OFunctorPre Nat) where [cmra [COFE α] [COFE β] : UCMRA (F α β)] map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x + 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) extends URFunctor F where +class URFunctorContractive (F : COFE.OFunctorPre Nat) extends URFunctor F where map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) @@ -1061,10 +1064,10 @@ 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] @@ -1153,7 +1156,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 +1171,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 _ @@ -1465,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 @@ -1613,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 => ⟨?_, ?_⟩⟩ @@ -1681,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))) := @@ -1741,7 +1744,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/COFESolver.lean b/Iris/Iris/Algebra/COFESolver.lean index 5706bb01d..06011178a 100644 --- a/Iris/Iris/Algebra/COFESolver.lean +++ b/Iris/Iris/Algebra/COFESolver.lean @@ -6,16 +6,19 @@ Authors: Mario Carneiro, Sebastian Graf module public import Iris.Algebra.OFE +public import Iris.Algebra.StepIndexFinite 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 {F : ∀ α β [COFE α] [COFE β], Type u} [OFunctorContractive F] +variable {F : ∀ α β [COFE α] [COFE β], Type u} [OFunctorContractive Nat F] variable [∀ α [COFE α], IsCOFE (F α α)] variable [inh : Inhabited (F (ULift Unit) (ULift Unit))] @@ -56,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 @@ -84,7 +87,7 @@ instance : OFE (Tower F) where 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" @@ -99,10 +102,13 @@ def towerChain (c : Chain (Tower F)) (k : Nat) : Chain (A F k) 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 + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore solver.tower_cofe "Use IsCOFE instance" #rocq_ignore solver.tower_compl "Use IsCOFE instance" @@ -201,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), @@ -260,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) _ } @@ -269,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 @@ -295,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 diff --git a/Iris/Iris/Algebra/Csum.lean b/Iris/Iris/Algebra/Csum.lean index 294bf395c..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] @@ -49,7 +51,7 @@ 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 @@ -153,6 +155,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 := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore csum_compl "Included in IsCOFE instance" @@ -229,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⟩ @@ -286,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 -/ @@ -543,7 +548,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] @@ -563,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 ea8bc26b9..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. -/ diff --git a/Iris/Iris/Algebra/DynReservationMap.lean b/Iris/Iris/Algebra/DynReservationMap.lean index 085c95d13..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 @@ -73,7 +75,7 @@ instance : OFE (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 8decf0908..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 @@ -50,7 +52,7 @@ 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 @@ -119,6 +121,9 @@ instance [OFE α] [IsCOFE α] : IsCOFE (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 := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) /-! ## CMRA -/ @[simp] def Valid : Excl α → Prop @@ -183,7 +188,7 @@ theorem excl_included [OFE α] {a b : α} : 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 α] {a b : α} {n} : @@ -257,10 +262,10 @@ instance oMap_ne [OFE α] [OFE β] : NonExpansive (oMap (α := α) (β := β)) w | 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 +286,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..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 -/ diff --git a/Iris/Iris/Algebra/Functions.lean b/Iris/Iris/Algebra/Functions.lean index cb237c378..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 diff --git a/Iris/Iris/Algebra/GenMap.lean b/Iris/Iris/Algebra/GenMap.lean index 7c23adeea..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 @@ -106,7 +108,7 @@ end OFE 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 ⊢ @@ -115,7 +117,7 @@ theorem GenMap.singleton_discreteE {v : β} [OFE β] [DiscreteE v] : · 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 - 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.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,16 +293,16 @@ 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 · 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 +312,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,7 +324,7 @@ 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 @@ -335,24 +337,24 @@ 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 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 -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 @@ -366,7 +368,7 @@ instance instURFunctor_GenMapOF (F : COFE.OFunctorPre) [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) [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 ⊢ @@ -388,7 +390,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..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 @@ -22,17 +24,17 @@ namespace PartialMap 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 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 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] @@ -46,7 +48,7 @@ instance [LawfulPartialMap M K] [OFE V] (k : K) : NonExpansive₂ (insert · k · 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 := - eq_dist.mpr fun _ k => Dist.of_eq (H k) + eq_dist (SI := Nat) |>.mpr fun _ k => Dist.of_eq (H k) instance [LawfulPartialMap M K] [OFE V] (op : K → V → V → V) [∀ k, NonExpansive₂ (op k)] : NonExpansive₂ (merge (M := M) op) where @@ -69,15 +71,18 @@ instance Heap.instCOFE [LawfulPartialMap M K] [COFE V] : COFE (M V) where 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 := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) instance instDiscreteHeap [LawfulPartialMap M K] [OFE V] [Discrete V] : Discrete (M V) where - discrete_0 h := OFE.eq_dist.mpr <| by + 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 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] @@ -88,7 +93,7 @@ instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE V] { simp [LawfulPartialMap.get?_singleton, hh, ↓reduceIte] instance instDiscreteEEmpty [LawfulPartialMap M K] [OFE V] : DiscreteE (∅ : M V) where - discrete {y} h := OFE.eq_dist.mpr <| by + 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 @@ -144,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 <;> @@ -179,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 <;> @@ -196,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 @@ -212,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 @@ -232,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] @@ -258,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] @@ -345,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] @@ -357,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 @@ -387,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 @@ -395,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 @@ -446,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 @@ -456,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 @@ -560,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 @@ -581,7 +586,7 @@ instance [OFE α] [OFE β] {f : α → β} [hne : OFE.NonExpansive f] : OFE.NonE apply OFE.NonExpansive.ne theorem map_id [OFE α] (a : H α) : - PartialMap.map H id a = a := OFE.eq_dist.mpr <| by + 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 @@ -597,7 +602,7 @@ theorem map_ne [OFE α] [OFE β] (f g : α -> β) {heq : f ≡{n}≡ g} : map H exact heq _ 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.mpr <| by + 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 @@ -612,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 @@ -621,16 +626,16 @@ 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 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 @@ -641,7 +646,7 @@ instance {F} [COFE.OFunctor F] : COFE.OFunctor (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] @@ -658,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 1610a221e..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 @@ -263,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 => ?_, ?_⟩ @@ -416,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] @@ -528,7 +530,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..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 @@ -22,7 +24,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 +47,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 +66,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 (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 23cf2fc84..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. 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 e1a3665b1..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 @@ -172,7 +174,7 @@ end Frac /-! ## Functors -/ @[rocq_alias dfrac_agreeRF] -abbrev DFracAgreeRF (T : COFE.OFunctorPre) [COFE.OFunctor T] : COFE.OFunctorPre := +abbrev DFracAgreeRF (T : COFE.OFunctorPre Nat) [COFE.OFunctor Nat T] : COFE.OFunctorPre Nat := ProdOF (constOF DFrac) (AgreeRF T) end DFracAgree diff --git a/Iris/Iris/Algebra/Lib/ExclAuth.lean b/Iris/Iris/Algebra/Lib/ExclAuth.lean index f08dc11ee..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 /-! @@ -107,11 +109,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..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 @@ -271,11 +273,11 @@ theorem updateP_both_unpersist {q : Qp} {a b : A} : /-! ## Functors -/ @[rocq_alias frac_authURF] -abbrev FracAuthURF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := +abbrev FracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := AuthURF (OptionOF (ProdOF (constOF (Qp)) T)) @[rocq_alias frac_authRF] -abbrev FracAuthF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := +abbrev FracAuthF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := AuthRF (OptionOF (ProdOF (constOF (Qp)) T)) end FracAuth diff --git a/Iris/Iris/Algebra/Lib/MonoNat.lean b/Iris/Iris/Algebra/Lib/MonoNat.lean index 31cc5078c..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) diff --git a/Iris/Iris/Algebra/Lib/UFracAuth.lean b/Iris/Iris/Algebra/Lib/UFracAuth.lean index 136e84709..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 @@ -213,13 +215,13 @@ 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 := +abbrev UFracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := 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) [RFunctor T] : COFE.OFunctorPre := +abbrev UFracAuthRF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := 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/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 e70bf9f38..42101b697 100644 --- a/Iris/Iris/Algebra/Monoid.lean +++ b/Iris/Iris/Algebra/Monoid.lean @@ -6,8 +6,11 @@ Authors: Zongyuan Liu module public import Iris.Algebra.OFE +public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.Algebra diff --git a/Iris/Iris/Algebra/Numbers.lean b/Iris/Iris/Algebra/Numbers.lean index 915a2722f..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 α] [Discrete α] +variable [OFE α] [OFE.Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [Zero α] [LawfulLeftIdentity (add (α := α)) zero] variable {x y x' y' : α} diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 82175557a..85cfc6349 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1,20 +1,24 @@ /- 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 +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 (α : Type _) where - Dist : Nat → α → α → Prop +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 dist_lt : Dist n x y → m < n → Dist m x y @@ -29,35 +33,39 @@ 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 => OFE.Dist (SI := stepindex%) n x y +scoped notation:40 x " ≡{" n "}≡@{" S "} " y:41 => OFE.Dist (SI := S) 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 α] {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 α] {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 := - if hm : m = n then hm ▸ h else h.lt (Nat.lt_of_le_of_ne h' hm) +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 α] {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 +@[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 α] {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 α] {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 {α β : 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 α] : NonExpansive (@id α) := ⟨fun _ _ _ h => h⟩ @@ -72,7 +80,8 @@ theorem NonExpansive.comp [OFE α] [OFE β] [OFE γ] {g : β → γ} {f : α → #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₂ {α β γ : 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" @@ -89,57 +98,58 @@ theorem NonExpansive₂.ne_left [OFE α] [OFE β] [OFE γ] (f : α → β → γ /-- `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 α] (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 α] {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 α] {n} {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 α] {n} : 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 α] {n} {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 α] {m n} {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 α] {x y : α} : DistLater 0 x y := nofun +@[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 α] {n} {x y : α} : DistLater n.succ x y ↔ x ≡{n}≡ y := - ⟨(·.dist_lt (Nat.lt_succ_self _)), fun h1 _ h2 => h1.le (Nat.le_of_lt_succ h2)⟩ +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 α] {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) +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 α] [OFE β] (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 α] [OFE β] (f : α → β) - [Contractive f] {x y} : f x ≡{0}≡ f y := + [Contractive f] {x y} : f x ≡{(0 : SI)}≡ 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 := + (h : x ≡{n}≡ y) : f x ≡{SIdx.succ n}≡ f y := Contractive.distLater_dist (distLater_succ.2 h) /-- A contractive function is non-expansive. -/ @@ -163,13 +173,13 @@ def ofDiscrete (α : Type _) : OFE α where /-- A discrete element in an OFE -/ @[rocq_alias Discrete] -class DiscreteE {α : Type _} [OFE α] (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 α] 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] @@ -180,14 +190,14 @@ theorem discreteE_eqv [OFE α] {x y : α} (h : x = y) : DiscreteE x ↔ Discrete /-- 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 := - discrete_0 (h.le (Nat.zero_le _)) +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 α] [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 α] [Discrete α] {n : SI} {x y : α} (h : x ≡{(0 : SI)}≡ y) : x ≡{n}≡ y := (discrete h).dist export OFE.Discrete (discrete_n) @@ -196,8 +206,8 @@ theorem Discrete.discrete_iff [OFE α] [Discrete α] (n) {x y : α} : x = 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 := - ⟨discrete_n, fun h => h.le (Nat.zero_le _)⟩ +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`." #rocq_ignore natO "Canonical Leibniz OFE on `nat`; Lean uses `ofDiscrete Nat`." @@ -211,7 +221,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 +236,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) : + (hlt : ∀ {n m : SI} {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 := + 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 +258,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 +289,27 @@ 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 _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] where f : α → β ne : NonExpansive f #rocq_ignore ofe_mor_proper "Derived from nonexpansivity" @@ -302,6 +318,9 @@ non-expansive. -/ @[inherit_doc] infixr:25 " -n> " => Hom +@[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 @@ -333,21 +352,24 @@ theorem Hom.comp_assoc [OFE α] [OFE β] [OFE γ] [OFE δ] def Hom.ofSubtype [OFE α] [OFE β] (f : { f : α → β // NonExpansive f }) : α -n> β := ⟨f.val, f.property⟩ -@[ext] structure ContractiveHom (α β : Type _) [OFE α] [OFE β] 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 +notation:25 α:26 " -c>@{" SI "} " β:25 => ContractiveHom α β SI + 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] : α -c> β where +def _root_.Function.toContractiveHom (f : α → β) [OFE α] [OFE β] [ι : OFE.Contractive f SI] : α -c> β where f := f contractive := ι -@[simp] theorem _root_.Function.toContractiveHom_apply {f : α → β} [OFE α] [OFE β] [ι : 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 @@ -355,8 +377,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 Unit where Dist _ _ _ := True dist_eqv := ⟨fun _ => ⟨⟩, id, fun _ => id⟩ eq_dist := by simp @@ -364,7 +386,9 @@ 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 _ _⟩ +instance : @DiscreteE Unit (() : Unit) SI instSI (unitOFE ) := + letI := unitOFE (SI := SI) + ⟨fun _ => Subsingleton.elim _ _⟩ instance [OFE α] : OFE (ULift α) where Dist n x y := x.down ≡{n}≡ y.down @@ -395,7 +419,7 @@ theorem _root_.Option.Forall₂.equivalence {R : α → α → Prop} 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." @@ -405,25 +429,25 @@ instance [OFE α] : OFE (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 α] {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 α] {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 {α : 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 α] {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 α] {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 α] {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 α] {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 α] {o : Option α} : o ≡{n}≡ none ↔ o = none := @@ -489,17 +513,17 @@ theorem Option.bind_equiv [OFE α] [OFE β] {x : Option α} {f g : α → Option | some _ => H _ | none => rfl -abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE (β a) +abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE (β a) SI @[rocq_alias discrete_fun_ofe_mixin] -instance [OFEFun (β : α → _)] : OFE ((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`." @@ -545,7 +569,7 @@ 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 @@ -553,11 +577,11 @@ def applyNe [OFE α] [OFE β] (x : α) : (α -n> β) -n> β where f f := f x ne.1 _ _ _ H := H x -instance [OFE α] [OFE β] : 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 β₂] +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) @@ -575,21 +599,21 @@ instance [OFE α] [OFE β] : OFE (α × β) where 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 α] [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 {α β : 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} [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 α] [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} [OFE α] [OFE β] {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] @@ -613,6 +637,7 @@ 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 α] [OFE β] [OFE γ] {f : α → β → γ} (hf : NonExpansive₂ f) : NonExpansive (Function.uncurry f) := ⟨fun {_ _ _} (h : _ ∧ _) => hf.ne h.1 h.2⟩ @@ -639,8 +664,8 @@ variable [OFE α] [OFE β] @[rocq_alias sum_ofe_mixin] 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 @@ -674,7 +699,9 @@ instance : OFE (α ⊕ β) 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] @@ -731,25 +758,25 @@ instance [OFE α] (P : α → Prop) : OFE (Subtype P) where @[rocq_alias sig_discrete] instance [OFE α] [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 α] (P : α → Prop) : NonExpansive (Subtype.val : Subtype P → α) where ne {_ _ _} := id -instance Hom.ofSubtype_ne [OFE α] [OFE β] : 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 α] [OFE β] (f : α -n> β) : { f : α → β // NonExpansive f } := ⟨f.f, f.ne⟩ -instance Hom.toSubtype_ne [OFE α] [OFE β] : 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 (P x)] : OFE (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 @@ -765,7 +792,7 @@ instance instOFESigma (P : α → Type _) [∀ x, OFE (P x)] : OFE (Sigma P) whe 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⟩ @@ -774,7 +801,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 (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⟩ @@ -782,51 +809,52 @@ 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 (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 (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 α] [∀ x, OFE (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 (P x)] {n} {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 (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 (P x)] {n} {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 (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 (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 α] [OFE β] 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 @@ -841,11 +869,11 @@ instance [OFE α] [OFE β] : CoeFun (Iso α β) (fun _ => α -n> β) := ⟨Iso.h 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 α] [OFE β] (iso : Iso α β) {n} {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 α] [OFE β] (iso : Iso α β) {n} {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 @@ -862,13 +890,13 @@ theorem Iso.inv_eqv [OFE α] [OFE β] (iso : Iso α β) ⦃x y⦄ : 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 α] [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 α] [OFE β] (iso : Iso α β) {n} ⦃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)⟩ @@ -905,21 +933,24 @@ 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 _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] where + chain : SI → α cauchy : n ≤ i → chain i ≡{n}≡ chain n -instance [OFE α] : CoeFun (Chain α) (fun _ => Nat → α) := ⟨Chain.chain⟩ +instance [SIdx SI] [OFE α] : 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 chain := fun _ => a cauchy _ := OFE.Dist.rfl -@[simp] theorem const_apply [OFE α] {a : α} {n} : 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] @@ -927,7 +958,7 @@ 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 α] [OFE β] {f : α -n> β} {c : Chain α} {n} : +@[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 α] {c : Chain α} : map (Hom.id : α -n> α) c = c := by @@ -940,18 +971,18 @@ theorem map_comp [OFE α] [OFE β] [OFE γ] {f : α -n> β} {g : β -n> γ} {c : 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 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 => ?_) - 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 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 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') @@ -973,18 +1004,58 @@ theorem chain_option_some [OFE V] {c : Chain (Option V)} (H : c n = some v) : rw [← Hchoose] simp [hcc] +@[rocq_alias bchain] +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 α] [OFE β] + +@[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 + +@[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 -/ @[rocq_alias Cofe] -class IsCOFE (α : Type _) [OFE α] 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 → α + 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 (α : Type _) := OFE α, IsCOFE α +class abbrev COFE (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] := 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 := conv_compl.trans (c.cauchy h).symm @@ -993,61 +1064,64 @@ theorem conv_compl' [COFE α] {c : Chain α} {n i} (h : n ≤ i) : compl c ≡{n @[rocq_alias compl_chain_map] 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 α] (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 α] [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 α := - let _ := OFE.ofDiscrete α - { compl := fun c => c 0 - conv_compl := fun {n c} => (c.cauchy (Nat.zero_le n)).symm } + letI : OFE α := OFE.ofDiscrete α + { + 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 α] : COFE (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ conv_compl := conv_compl + 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 Unit where - discrete_0 _ := Subsingleton.elim _ _ - -@[rocq_alias unit_cofe] -instance : COFE Unit where - compl _ := () - conv_compl := ⟨⟩ +instance : @Discrete Unit SI _ unitOFE := + letI : OFE Unit := unitOFE + { discrete_0 _ := Subsingleton.elim _ _ } + +@[reducible, rocq_alias unit_cofe] +def unitCOFE : COFE Unit := + letI : OFE Unit := unitOFE + { + compl _ := () + conv_compl := ⟨⟩ + lbcompl _ _ := () + conv_lbcompl _ _ _ _ := ⟨⟩ + lbcompl_ne _ _ _ _ _ := ⟨⟩ + } -abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun β] := ∀ x : α, IsCOFE (β x) +abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE (β x) -instance instIsCOFEOption [OFE α] [IsCOFE α] : IsCOFE (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 (Nat.zero_le 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 (by omega : 0 ≤ n)).elim - | some _ => rfl #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 (β 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)) + 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] @@ -1057,15 +1131,27 @@ instance instIsCOFEHom [OFE α] [OFE β] [IsCOFE β] : IsCOFE (α -n> β) where refine conv_compl.trans (.trans ?_ conv_compl.symm) exact NonExpansive.ne (f := c.chain n) H conv_compl _ := IsCOFE.conv_compl + 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 α] [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 := + (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).left), + IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).right)⟩ @[rocq_alias sum_cofe] -instance instIsCOFESum [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α ⊕ β) 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⟩)) @@ -1076,36 +1162,98 @@ instance instIsCOFESum [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α 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 + 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 + 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 <;> 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." #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)] - (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy (by omega : 0 ≤ n)).choose +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 (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 (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 + 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 (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 + 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 (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 (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 + +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 @[rocq_alias chain_map_snd] -def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (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 := 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 (P x)] [∀ x, IsCOFE (P x)] : IsCOFE (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, ?_⟩ @@ -1116,26 +1264,47 @@ instance {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P x)] : IsCOFE ( revert heq; cases c.chain n rintro ⟨⟩ hequiv exact hequiv + 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 -abbrev OFunctorPre := ∀ α β [COFE α] [COFE β], 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 (F : OFunctorPre) where +class OFunctor (SI) [SIdx SI] (F : OFunctorPre SI) where ofe [COFE α] [COFE β] : OFE (F α β) map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -n> F α₂ β₂ map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x + 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 (F : OFunctorPre) extends OFunctor F where +class OFunctorContractive SI [SIdx SI] (F : OFunctorPre SI) extends OFunctor SI F where map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) @@ -1147,27 +1316,35 @@ end COFE @[ext] structure DiscreteO (α : Type _) where car : α -instance : COFE (DiscreteO α) := COFE.ofDiscrete _ +@[reducible] +def DiscreteO.instCOFE [SIdx SI] {α : Type _} : COFE (DiscreteO α) := COFE.ofDiscrete _ -instance {α : Type _} : OFE.Discrete (DiscreteO α) := ⟨fun h => h⟩ +theorem DiscreteO.OFE [SIdx SI] {α : Type _} : + @OFE.Discrete (DiscreteO α) SI _ (OFE.ofDiscrete _) := + letI : Iris.OFE (DiscreteO α) := Iris.OFE.ofDiscrete _ + ⟨id⟩ #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 : COFE (DiscreteO α) := DiscreteO.instCOFE + DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := + fun H => DiscreteO.eqv_inj 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 +1352,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 α] @[rocq_alias option_chain] def optionChain (c : Chain (Option α)) (x : α) : Chain α := by @@ -1190,14 +1368,49 @@ 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 α] : IsCOFE (Option α) where compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x) - conv_compl {n} c := by - have := c.cauchy (Nat.zero_le n); revert this + conv_compl {n : SI} c := by + 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] + 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 rw [f1, f2] at hp' + | none => exact h0 + | some _ => exact hp'.elim + | some _ => + 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 α] [OFE β] (f : α -n> β) : Option α -n> Option β := by @@ -1206,7 +1419,7 @@ def optionMap {α β : Type _} [OFE α] [OFE β] (f : α -n> β) : Option α -n> 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 β] {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₂] @@ -1215,7 +1428,7 @@ 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 β] : 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) @@ -1225,12 +1438,12 @@ theorem Option.bind_ne [OFE β] {f g : α → Option β} {x y : Option α} {n} 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 +1452,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 +1476,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 +1487,7 @@ section ProdOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE 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] : @@ -1300,14 +1515,16 @@ 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 (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 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 +1533,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 F1 F2) where map_contractive.1 H _ := Prod.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) @@ -1327,7 +1544,7 @@ section SumOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE 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] : @@ -1356,14 +1573,14 @@ 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 (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 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 +1595,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 F1 F2) where map_contractive.1 H _ := Sum.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) @@ -1389,19 +1606,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 (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 _ _⟩⟩ 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 +1630,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 +1640,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 B] : OFunctor SI (constOF B) where ofe := _ map _ _ := ⟨id, id_ne⟩ map_ne := by intros; constructor; simp @@ -1432,7 +1653,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 B] : OFunctorContractive SI (constOF B) where map_contractive.1 := by simp [OFunctor.map] end constOF @@ -1441,11 +1662,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 _) (_ : COFE 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 +1681,7 @@ section HomOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE 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 @@ -1469,34 +1692,31 @@ 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) [OFunctor F1] [OFunctor F2] : OFunctorPre := +abbrev HomOF (F1 F2 : OFunctorPre SI) [OFunctor SI F1] [OFunctor SI F2] : OFunctorPre SI := fun (A : Type _) (B : Type _) (_ : COFE A) (_ : COFE 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) - 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 @[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') := - 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).right, (h m hm).left⟩ refine NonExpansive₂.ne ?_ ?_ · exact (map_contractive (F := F1)).1 h' · exact (map_contractive (F := F2)).1 h @@ -1505,136 +1725,244 @@ end HomOF section Fixpoint +variable [instSI : SIdx SI] + @[rocq_alias LimitPreserving] -def LimitPreserving [COFE α] (P : α → Prop) : Prop := - ∀ (c : Chain α), (∀ n, P (c n)) → P (COFE.compl c) +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 α] {P : Prop} : LimitPreserving fun (_ : α) => P := by - simp [LimitPreserving] +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 α] {P : α → Prop} : - (∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) → LimitPreserving P := - fun Hdisc _ H => Hdisc COFE.conv_compl.symm (H _) +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 α] {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)⟩ + (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 α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P y)) : - LimitPreserving (∀ y, P y ·) := - 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 α] (P1 P2 : α → Prop) - (HP1 : ∀ {x y : α}, x ≡{0}≡ y → P1 x → P1 y) + (HP1 : ∀ {x y : α}, x ≡{(0 : SI)}≡ 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) + 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 α] {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 α] [COFE β] (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' (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 @[rocq_alias limit_preserving_ext] -theorem LimitPreserving.ext {α}[COFE α] {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 - chain n := Nat.repeat f (n + 1) default - cauchy {n} := 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) +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 α] [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 := 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 := by + unfold bcompl + rcases hcase : SIdx.case n with h0 | ⟨p, hp⟩ | hlim + · 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) := 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 [COFE α] [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 := 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 := 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) + +@[rocq_alias fixpoint_bchain] +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) := + instSI.lt_wf.fix_eq (BFChain.go f) n + +end BFChain + +@[rocq_alias fixpoint_chain] +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) + · exact Contractive.distLater_dist fun p Hp => + BFChain.unique f (fixpointBFChain f i) (fixpointBFChain f n) p + (SIdx.lt_trans Hp Hni) Hp + · rfl /-- 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] : α := - COFE.compl <| Fixpoint.chain f + COFE.compl <| Fixpoint.chain (SI := SI) f theorem fixpointAux_unfold [COFE α] [Inhabited α] (f : α -c> α) : - fixpointAux f = f (fixpointAux f) := by - refine eq_dist.mpr fun n => ?_ + 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) - induction n with - | zero => exact Contractive.zero f.f - | succ _ IH => exact (Contractive.succ f.f IH.symm).symm + 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 elaborator and the kernel, which keeps the approximation chain of `fixpointAux` sealed. -/ opaque fixpointP [COFE α] [Inhabited α] (f : α → α) [Contractive f] : { x : α // x = f x } := - ⟨fixpointAux f, fixpointAux_unfold f.toContractiveHom⟩ + ⟨fixpointAux (SI := SI) f, fixpointAux_unfold f.toContractiveHom⟩ /-- Fixpoints inside of a COFE -/ @[rocq_alias fixpoint] def fixpoint [COFE α] [Inhabited α] (f : α → α) [Contractive f] : α := - (fixpointP f).val + (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 α] [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 α] [Inhabited α] (f : α -c> α) : - fixpoint f = f (fixpoint f) := + fixpoint (SI := SI) f = f (fixpoint (SI := SI) f) := (fixpointP f).property @[rocq_alias fixpoint_unique] -theorem fixpoint_unique [COFE α] [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 +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 α] [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 _) + 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 + 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 α] [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 + obtain ⟨y, hy, hfy⟩ : ∃ y : α, P y ∧ y = f y := by + letI : Inhabited α := ⟨x⟩ + 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 + | h n ih => + refine LimitPreserving.bcompl n _ (.inr Hbase) Hlim fun m hm => ?_ + rw [fixpointBFChain_unfold] + exact Hind _ (ih m hm) + · exact fixpointAux_unfold f + exact HProper _ _ (fixpoint_unique hfy) hy end Fixpoint @@ -1642,6 +1970,8 @@ section FixpointAB open OFE +variable [SIdx SI] + 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⟩ @@ -1680,7 +2010,7 @@ def fixpointAA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β @[rocq_alias fixpoint_AA_contractive] theorem fixpointAA_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : Contractive (fixpointAA fA fB) where + (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 @@ -1697,37 +2027,39 @@ def fixpointA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β @[rocq_alias fixpoint_B] def fixpointB [COFE α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : β := + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) : β := fixpointAB fB <| fixpointA fA fB @[rocq_alias fixpoint_A_unfold] theorem fixpointA_unfold [COFE α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : + (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 α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : + (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 α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) (Hp : fA p q = p) (Hq : fB p q = q) : + (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 α] [COFE β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) (Hp : fA p q = p) (Hq : fB p q = q) : + (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 α] [COFE β] [Inhabited α] [Inhabited β] : - NonExpansive₂ (fixpointA (α := α) (β := β)) where + NonExpansive₂ (fixpointA (SI := SI) (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply OFE.ContractiveHom.fixpoint_ne.ne intro z₁ @@ -1736,7 +2068,7 @@ instance fixpointA_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : @[rocq_alias fixpoint_B_ne] instance fixpointB_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : - NonExpansive₂ (fixpointB (α := α) (β := β)) where + NonExpansive₂ (fixpointB (SI := SI) (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply ContractiveHom.fixpoint_ne.ne intro z₁ @@ -1747,6 +2079,8 @@ end FixpointAB section Later +variable [SIdx SI] + @[rocq_alias later] structure Later (A : Type u) : Type u where next :: car : A @@ -1756,9 +2090,9 @@ instance isOFE_later [OFE A] : OFE (Later A) where dist_eqv := ⟨fun _ => .rfl, .symm, .trans⟩ 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) + 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" #rocq_ignore later_equiv "Local Equiv instance; folded into Lean's OFE (Later A) instance." @@ -1772,19 +2106,34 @@ instance NextContractive {A : Type _} [OFE A] : Contractive (@Later.next A) wher @[rocq_alias later_chain] def laterChain [OFE 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_limit_bchain] +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 A] [IsCOFE A] : IsCOFE (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) conv_compl {n} 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) + 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 + 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 := + 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 A] [OFE 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) @@ -1799,13 +2148,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 +2164,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 : α} - (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/ReservationMap.lean b/Iris/Iris/Algebra/ReservationMap.lean index 2bfc7bc0a..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 /-! @@ -77,7 +79,7 @@ instance : OFE (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 new file mode 100644 index 000000000..eefc6b496 --- /dev/null +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -0,0 +1,60 @@ +/- +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 + +local stepindex Nat + +namespace Iris + +@[rocq_alias natSI, rocq_alias nat_sidx_mixin] +instance natSIdx : SIdx Nat where + 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 .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 + | 0 => .inr (by omega) + | m + 1 => .inl ⟨_, rfl⟩ + +@[rocq_alias nat_sidx_finite] +instance natSIdxFinite : SIdxFinite Nat where + 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 := SIdx.limit_finite n h |>.elim + +namespace OFE + +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 α] [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 (DiscreteO α) := DiscreteO.instCOFE + +instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (DiscreteO α) := + DiscreteO.OFE + +instance unitCOFE_Nat : COFE Unit := COFE.unitCOFE + +end OFE diff --git a/Iris/Iris/Algebra/StepIndexRegistry.lean b/Iris/Iris/Algebra/StepIndexRegistry.lean new file mode 100644 index 000000000..7eb94088a --- /dev/null +++ b/Iris/Iris/Algebra/StepIndexRegistry.lean @@ -0,0 +1,59 @@ +/- +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)}" + +/-- +`stepindex%` elaborates to the step index type in scope, resolved **eagerly** as a term. +-/ +@[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. + +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/Algebra/UFrac.lean b/Iris/Iris/Algebra/UFrac.lean index 6ee7910e8..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] diff --git a/Iris/Iris/Algebra/UPred.lean b/Iris/Iris/Algebra/UPred.lean index 3adf78773..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 @@ -106,10 +108,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 := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #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,23 +128,23 @@ 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 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] @[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/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 d1a0c555c..0e8e98404 100644 --- a/Iris/Iris/Algebra/View.lean +++ b/Iris/Iris/Algebra/View.lean @@ -16,6 +16,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + open Iris abbrev ViewRel (A B : Type _) := Nat → A → B → Prop @@ -70,7 +72,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 (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) : @@ -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 @@ -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 @@ -825,7 +827,7 @@ section mapO variable [OFE A] [OFE B] [OFE A'] [OFE B'] {R : ViewRel A B} {R' : ViewRel A' B'} theorem map_compose' [OFE A''] [OFE B''] {R'' : ViewRel A'' B''} - f g (f' : A' -n> A'') (g' : B' -n> B'') (v : View R) : + (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 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 fc6806e3a..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 diff --git a/Iris/Iris/BI/BI.lean b/Iris/Iris/BI/BI.lean index 353cfe7e8..9e676fb2b 100644 --- a/Iris/Iris/BI/BI.lean +++ b/Iris/Iris/BI/BI.lean @@ -6,10 +6,13 @@ 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 +local stepindex Nat + namespace Iris open Iris.Std OFE open Lean 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 00ed9a6eb..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 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 ad57deb0d..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 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 db9b594bd..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] -theorem LimitPreserving.entails [BI PROP] [COFE 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⟩)⟩ @@ -2391,34 +2393,34 @@ 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_emp_valid] -theorem limitPreserving_emp_valid [BI PROP] [COFE 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 A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : - LimitPreserving (fun x => Persistent (Φ x)) := by + 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 + 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)) _ ?_ + 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/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 f20eaba10..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 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 0a449a954..e8a78d5c4 100644 --- a/Iris/Iris/BI/InternalEq.lean +++ b/Iris/Iris/BI/InternalEq.lean @@ -11,6 +11,8 @@ public import Iris.Algebra.Excl @[expose] public section +local stepindex Nat + namespace Iris open BI OFE Iris.Std @@ -119,7 +121,7 @@ theorem discrete_eq {A : Type _} [OFE A] {a b : A} [TCOr (DiscreteE a) (Discrete ⟨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) @@ -226,7 +228,7 @@ theorem csum_equivI {A B : Type _} [OFE A] [OFE 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,7 +237,7 @@ 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⟩ @@ -328,12 +330,12 @@ instance eq_timeless {A : Type _} [OFE A] (a b : A) [TCOr (DiscreteE a) (Discret @[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] 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 5ce180e82..37e979ab0 100644 --- a/Iris/Iris/BI/Lib/Fixpoint.lean +++ b/Iris/Iris/BI/Lib/Fixpoint.lean @@ -10,6 +10,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI OFE 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 99f510fbd..8462f84a3 100644 --- a/Iris/Iris/BI/Lib/MonoNat.lean +++ b/Iris/Iris/BI/Lib/MonoNat.lean @@ -13,10 +13,12 @@ public import Iris.Instances.IProp @[expose] public section +local stepindex Nat + namespace Iris open Auth BI MonoNat -abbrev MonoNatRF : COFE.OFunctorPre := +abbrev MonoNatRF : COFE.OFunctorPre Nat := AuthURF (constOF MaxNat) @[rocq_alias mono_natG] @@ -139,7 +141,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/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 da9067ee7..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 @@ -155,10 +157,13 @@ instance : IsCOFE (MonPred I PROP) where 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 (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)) + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) end OFE diff --git a/Iris/Iris/BI/Plainly.lean b/Iris/Iris/BI/Plainly.lean index 75ed12a88..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,11 +419,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 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 diff --git a/Iris/Iris/BI/SIProp.lean b/Iris/Iris/BI/SIProp.lean index b22b0230f..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) @@ -131,6 +133,9 @@ instance : IsCOFE 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 := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore siProp_compl "Included in IsCOFE instance." @@ -317,7 +322,7 @@ theorem internalEq_entails [OFE A] [OFE B] (a₁ a₂ : A) (b₁ b₂ : 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⟩ 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 d814de9cd..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. @@ -27,7 +29,7 @@ open Iris OFE COFE variable [OFE Val] [OFE Err] [IsCOFE Val] [IsCOFE Err] [Inhabited Err] -abbrev DomF : OFunctorPre := +abbrev DomF : OFunctorPre Nat := SumOF (constOF Val) (SumOF (constOF Err) (SumOF (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) instance : Inhabited (DomF (Val := Val) (Err := Err) (ULift Unit) (ULift Unit)) := 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 87984805c..a157fe721 100644 --- a/Iris/Iris/Examples/IProp.lean +++ b/Iris/Iris/Examples/IProp.lean @@ -13,12 +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 := constOF (Agree (DiscreteO String)) +abbrev F0 : OFunctorPre Nat := constOF (Agree (DiscreteO String)) +instance discreteO_cofe {α : Type _} : COFE (DiscreteO α) := DiscreteO.instCOFE +instance discreteO_discrete {α : Type _} : OFE.Discrete (DiscreteO α) := DiscreteO.OFE variable {GF} [E0 : ElemG GF F0] @@ -52,7 +56,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 +102,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 @@ -133,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( @@ -141,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 b0d75ef87..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 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 c70d83395..2369e614f 100644 --- a/Iris/Iris/Instances/IProp/Instance.lean +++ b/Iris/Iris/Instances/IProp/Instance.lean @@ -13,20 +13,22 @@ 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) (T : Type _) [COFE 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 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 := +/-- 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 @@ -61,7 +63,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, ‹_›⟩ @@ -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] @@ -443,10 +445,10 @@ 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 τ => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun n τ => ?_ simp only [iSingleton] at ⊢ split next h => @@ -460,7 +462,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 ⊢ @@ -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 9362f07c1..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 @@ -23,7 +25,7 @@ abbrev BoolO := DiscreteO Bool variable (GF : BundledGFunctors) -abbrev BoxF : OFunctorPre := +abbrev BoxF : OFunctorPre Nat := ProdOF (AuthURF (OptionOF (ExclOF (constOF BoolO)))) (OptionOF (AgreeRF (LaterOF IdOF))) diff --git a/Iris/Iris/Instances/Lib/CInvariants.lean b/Iris/Iris/Instances/Lib/CInvariants.lean index bec1f22c9..ac6b99c5b 100644 --- a/Iris/Iris/Instances/Lib/CInvariants.lean +++ b/Iris/Iris/Instances/Lib/CInvariants.lean @@ -18,13 +18,15 @@ public import Iris.Std.List @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA OFE Iris Std LawfulSet Excl COFE ProofMode /-! # Cancelable Invariants -/ -abbrev CInvF : OFunctorPre := +abbrev CInvF : OFunctorPre Nat := ProdOF (constOF (Option (Excl Unit))) (constOF (Option Qp)) @[rocq_alias cinvG] 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 955b663f3..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 @@ -228,7 +230,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 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 1f1847af6..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 @@ -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 f3ff10010..191f55be8 100644 --- a/Iris/Iris/Instances/Lib/NaInvariants.lean +++ b/Iris/Iris/Instances/Lib/NaInvariants.lean @@ -15,11 +15,13 @@ public import Iris.Std.CoPset @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA OFE Iris Std LawfulSet DisjointLeibnizSet COFE ProofMode -abbrev NaInvF : OFunctorPre := +abbrev NaInvF : OFunctorPre Nat := ProdOF (constOF CoPsetDisjL) (constOF (DisjointLeibnizSet PosSet)) @[rocq_alias na_invG] diff --git a/Iris/Iris/Instances/Lib/SavedProp.lean b/Iris/Iris/Instances/Lib/SavedProp.lean index 76a0c4acf..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 @@ -21,7 +23,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 +32,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..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 @@ -21,7 +23,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/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 680a027d9..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 @@ -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 a777b4531..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 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 990addc76..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 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 000ac373d..0e26f6b38 100644 --- a/Iris/Iris/ProofMode/Tactics/Rewrite.lean +++ b/Iris/Iris/ProofMode/Tactics/Rewrite.lean @@ -13,6 +13,8 @@ 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 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 new file mode 100644 index 000000000..02944b8b3 --- /dev/null +++ b/Iris/Iris/Tests/StepIndexRegistry.lean @@ -0,0 +1,271 @@ +/- +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 + +-- 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) + +section +variable {SI : Type} +local stepindex SI + +/-- info: SI -/ +#guard_msgs in +#stepindex? + +/-- info: SI : Type -/ +#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 -/ +#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 + +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/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 diff --git a/Iris/Iris/Tests/Tactics.lean b/Iris/Iris/Tests/Tactics.lean index a93db72a9..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 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 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