Skip to content

Commit 65273e6

Browse files
committed
Revert previous commits that eliminat Std/Classes.lean, only get rid of Reflexivity, Transitivity and Preorder
Reverts commits aa5e99e, 88bea9b and 96462af.
1 parent aa5e99e commit 65273e6

15 files changed

Lines changed: 123 additions & 29 deletions

Iris/Iris/BI/BIBase.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Lars König, Mario Carneiro
66
module
77

88
public meta import Iris.BI.Notation
9+
public import Iris.Std.Classes
910
public meta import Iris.Std.DelabRule
1011
public meta import Iris.Std.Rewrite
1112
public import Iris.Std.BigOp

Iris/Iris/BI/DerivedLaws.lean

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public import Iris.BI.Classes
99
public import Iris.BI.Extensions
1010
public import Iris.BI.BI
1111
public import Iris.Std.Nat
12+
public import Iris.Std.Classes
1213
public import Iris.Std.Rewrite
1314
public import Iris.Std.TC
1415
import Iris.Std.RocqPorting
@@ -23,7 +24,8 @@ open Iris.Std BI
2324
/- Necessary for `calc`-style proofs. -/
2425
instance entails_trans' [BI PROP] : Trans (α := PROP) Entails Entails Entails where
2526
trans h1 h2 := h1.trans h2
26-
27+
instance entails_antisymm [BI PROP] : Antisymmetric (α := PROP) BiEntails Entails where
28+
antisymm h1 h2 := ⟨h1, h2⟩
2729
#rocq_ignore bi.entails_proper "Derivable from _ne with NonExpansive.eqv."
2830

2931
instance equiv_trans [BI PROP] : Trans (α := PROP) BiEntails BiEntails BiEntails where
@@ -207,11 +209,13 @@ theorem exists_mono [BI PROP] {Φ Ψ : α → PROP} (h : ∀ a, Φ a ⊢ Ψ a) :
207209
theorem exists_congr [BI PROP] {Φ Ψ : α → PROP} (h : ∀ a, Φ a ⊣⊢ Ψ a) : (∃ a, Φ a) ⊣⊢ ∃ a, Ψ a :=
208210
⟨exists_mono fun a => (h a).1, exists_mono fun a => (h a).2
209211

210-
@[rocq_alias bi.and_idem]
211212
theorem and_self [BI PROP] {P : PROP} : P ∧ P ⊣⊢ P := ⟨and_elim_l, and_intro .rfl .rfl⟩
213+
@[rocq_alias bi.and_idem]
214+
instance [BI PROP] : Idempotent (α := PROP) BiEntails and := ⟨and_self⟩
212215

213-
@[rocq_alias bi.or_idem]
214216
theorem or_self [BI PROP] {P : PROP} : P ∨ P ⊣⊢ P := ⟨or_elim .rfl .rfl, or_intro_l⟩
217+
@[rocq_alias bi.or_idem]
218+
instance [BI PROP] : Idempotent (α := PROP) BiEntails or := ⟨or_self⟩
215219

216220
#rocq_ignore bi.and_mono' "Use and_mono"
217221
#rocq_ignore bi.and_flip_mono' "Use and_mono"
@@ -226,48 +230,61 @@ theorem or_self [BI PROP] {P : PROP} : P ∨ P ⊣⊢ P := ⟨or_elim .rfl .rfl,
226230

227231
@[rocq_alias bi.and_comm]
228232
theorem and_comm [BI PROP] {P Q : PROP} : P ∧ Q ⊣⊢ Q ∧ P := ⟨and_symm, and_symm⟩
233+
instance [BI PROP] : Commutative (α := PROP) BiEntails and := ⟨and_comm⟩
229234

230235
@[rocq_alias bi.or_comm]
231236
theorem or_comm [BI PROP] {P Q : PROP} : P ∨ Q ⊣⊢ Q ∨ P := ⟨or_symm, or_symm⟩
237+
instance [BI PROP] : Commutative (α := PROP) BiEntails or := ⟨or_comm⟩
232238

233239
@[rocq_alias bi.True_and]
234240
theorem true_and [BI PROP] {P : PROP} : True ∧ P ⊣⊢ P :=
235241
⟨and_elim_r, and_intro (pure_intro trivial) .rfl⟩
242+
instance [BI PROP] : LeftId (· ⊣⊢@{PROP} ·) iprop(True) and := ⟨true_and⟩
236243

237244
@[rocq_alias bi.and_True]
238245
theorem and_true [BI PROP] {P : PROP} : P ∧ True ⊣⊢ P := and_comm.trans true_and
246+
instance [BI PROP] : RightId (· ⊣⊢@{PROP} ·) iprop(True) and := ⟨and_true⟩
239247

240248
@[rocq_alias bi.False_and]
241249
theorem false_and [BI PROP] {P : PROP} : False ∧ P ⊣⊢ False := ⟨and_elim_l, false_elim⟩
250+
instance [BI PROP] : LeftAbsorb (· ⊣⊢@{PROP} ·) iprop(False) and := ⟨false_and⟩
242251

243252
@[rocq_alias bi.and_False]
244253
theorem and_false [BI PROP] {P : PROP} : P ∧ False ⊣⊢ False := and_comm.trans false_and
254+
instance [BI PROP] : RightAbsorb (· ⊣⊢@{PROP} ·) iprop(False) and := ⟨and_false⟩
245255

246256
@[rocq_alias bi.True_or]
247257
theorem true_or [BI PROP] {P : PROP} : True ∨ P ⊣⊢ True := ⟨true_intro, or_intro_l⟩
258+
instance [BI PROP] : LeftAbsorb (· ⊣⊢@{PROP} ·) iprop(True) or := ⟨true_or⟩
248259

249260
@[rocq_alias bi.or_True]
250261
theorem or_true [BI PROP] {P : PROP} : P ∨ True ⊣⊢ True := or_comm.trans true_or
262+
instance [BI PROP] : RightAbsorb (· ⊣⊢@{PROP} ·) iprop(True) or := ⟨or_true⟩
251263

252264
@[rocq_alias bi.False_or]
253265
theorem false_or [BI PROP] {P : PROP} : False ∨ P ⊣⊢ P := ⟨or_elim false_elim .rfl, or_intro_r⟩
266+
instance [BI PROP] : LeftId (α := PROP) BiEntails iprop(False) or := ⟨false_or⟩
254267

255268
@[rocq_alias bi.or_False]
256269
theorem or_false [BI PROP] {P : PROP} : P ∨ False ⊣⊢ P := or_comm.trans false_or
270+
instance [BI PROP] : RightId (α := PROP) BiEntails iprop(False) or := ⟨or_false⟩
257271

258272
@[rocq_alias bi.and_assoc]
259273
theorem and_assoc [BI PROP] {P Q R : PROP} : (P ∧ Q) ∧ R ⊣⊢ P ∧ Q ∧ R :=
260274
⟨and_intro (and_elim_left_trans and_elim_l) (and_mono_left and_elim_r),
261275
and_intro (and_mono_right and_elim_l) (and_elim_right_trans and_elim_r)⟩
276+
instance [BI PROP] : Associative (α := PROP) BiEntails and := ⟨and_assoc⟩
262277

263278
@[rocq_alias bi.or_assoc]
264279
theorem or_assoc [BI PROP] {P Q R : PROP} : (P ∨ Q) ∨ R ⊣⊢ P ∨ Q ∨ R :=
265280
⟨or_elim (or_mono_right or_intro_l) (or_intro_right_trans or_intro_r),
266281
or_elim (or_intro_left_trans or_intro_l) (or_mono_left or_intro_r)⟩
282+
instance [BI PROP] : Associative (α := PROP) BiEntails or := ⟨or_assoc⟩
267283

268284
@[rocq_alias bi.True_impl]
269285
theorem true_imp [BI PROP] {P : PROP} : (True → P) ⊣⊢ P :=
270286
⟨and_true.2.trans imp_elim_left, imp_intro and_elim_l⟩
287+
instance [BI PROP] : LeftId (· ⊣⊢@{PROP} ·) iprop(True) imp := ⟨true_imp⟩
271288

272289
@[rocq_alias bi.impl_refl]
273290
theorem imp_self [BI PROP] {P Q : PROP} : Q ⊢ P → P := imp_intro and_elim_r
@@ -373,7 +390,7 @@ instance bi_and_monoid [BI PROP] : LawfulBigOp and (iprop(True) : PROP) BiEntail
373390
trans h1 h2 := h1.trans h2
374391
comm := and_comm
375392
assoc := and_assoc
376-
left_id := true_and
393+
left_id := left_id
377394
congr_l := and_congr_left
378395

379396
/-! # BI -/
@@ -418,11 +435,13 @@ theorem wand_congr_right [BI PROP] {P Q Q' : PROP} (h : Q ⊣⊢ Q') : (P -∗ Q
418435

419436
@[rocq_alias bi.sep_comm]
420437
theorem sep_comm [BI PROP] {P Q : PROP} : P ∗ Q ⊣⊢ Q ∗ P := ⟨sep_symm, sep_symm⟩
438+
instance [BI PROP] : Commutative (α := PROP) BiEntails sep := ⟨sep_comm⟩
421439

422440
@[rocq_alias bi.sep_assoc]
423441
theorem sep_assoc [BI PROP] {P Q R : PROP} : (P ∗ Q) ∗ R ⊣⊢ P ∗ Q ∗ R :=
424442
⟨sep_assoc_l, (sep_comm.trans <| sep_congr_left sep_comm).1.trans <|
425443
sep_assoc_l.trans (sep_comm.trans <| sep_congr_right sep_comm).2
444+
instance [BI PROP] : Associative (α := PROP) BiEntails sep := ⟨sep_assoc⟩
426445

427446
theorem sep_left_comm [BI PROP] {P Q R : PROP} : P ∗ Q ∗ R ⊣⊢ Q ∗ P ∗ R :=
428447
sep_assoc.symm.trans <| (sep_congr_left sep_comm).trans sep_assoc
@@ -433,10 +452,12 @@ theorem sep_right_comm [BI PROP] {P Q R : PROP} : (P ∗ Q) ∗ R ⊣⊢ (P ∗
433452
theorem sep_sep_sep_comm [BI PROP] {P Q R S : PROP} : (P ∗ Q) ∗ (R ∗ S) ⊣⊢ (P ∗ R) ∗ (Q ∗ S) :=
434453
sep_assoc.trans <| (sep_congr_right sep_left_comm).trans sep_assoc.symm
435454

436-
#rocq_ignore bi.emp_sep "The type class LeftId in Lean is not general enough"
455+
@[rocq_alias bi.emp_sep]
456+
instance [BI PROP] : LeftId (α := PROP) BiEntails emp sep := ⟨emp_sep⟩
437457

438-
@[rocq_alias bi.sep_emp]
439458
theorem sep_emp [BI PROP] {P : PROP} : P ∗ emp ⊣⊢ P := sep_comm.trans emp_sep
459+
@[rocq_alias bi.sep_emp]
460+
instance [BI PROP] : RightId (α := PROP) BiEntails emp sep := ⟨sep_emp⟩
440461

441462
@[rocq_alias bi.bi_sep_monoid]
442463
instance bi_sep_monoid [BI PROP] : LawfulBigOp sep (emp : PROP) BiEntails where
@@ -445,7 +466,7 @@ instance bi_sep_monoid [BI PROP] : LawfulBigOp sep (emp : PROP) BiEntails where
445466
trans h1 h2 := h1.trans h2
446467
comm := sep_comm
447468
assoc := sep_assoc
448-
left_id := emp_sep
469+
left_id := left_id
449470
congr_l := sep_congr_left
450471

451472
@[rocq_alias bi.True_sep_2]
@@ -466,12 +487,16 @@ theorem wand_elim_swap [BI PROP] {P Q R : PROP} (h : Q ⊢ P -∗ R) : P ∗ Q
466487
@[rocq_alias bi.wand_elim_l]
467488
theorem wand_elim_left [BI PROP] {P Q : PROP} : (P -∗ Q) ∗ P ⊢ Q := wand_elim .rfl
468489

469-
@[rocq_alias bi.False_sep]
470490
theorem false_sep [BI PROP] {P : PROP} : False ∗ P ⊣⊢ False :=
471491
⟨(sep_mono_left (P' := iprop(P -∗ False)) false_elim).trans wand_elim_left, false_elim⟩
492+
@[rocq_alias bi.False_sep]
493+
instance [BI PROP] : LeftAbsorb (· ⊣⊢@{PROP} ·) iprop(False) sep where
494+
left_absorb := false_sep
472495

473-
@[rocq_alias bi.sep_False]
474496
theorem sep_false [BI PROP] {P : PROP} : P ∗ False ⊣⊢ False := sep_comm.trans false_sep
497+
@[rocq_alias bi.sep_False]
498+
instance [BI PROP] : RightAbsorb (· ⊣⊢@{PROP} ·) iprop(False) sep where
499+
right_absorb := sep_false
475500

476501
@[rocq_alias bi.wand_elim_r]
477502
theorem wand_elim_right [BI PROP] {P Q : PROP} : P ∗ (P -∗ Q) ⊢ Q := wand_elim_swap .rfl
@@ -1002,13 +1027,13 @@ theorem affinely_intro [BI PROP] {P Q : PROP} [Affine P] (h : P ⊢ Q) : P ⊢ <
10021027
@[rocq_alias bi.emp_and]
10031028
theorem emp_and [BI PROP] {P : PROP} [Affine P] : emp ∧ P ⊣⊢ P :=
10041029
⟨and_elim_r, and_intro affine .rfl⟩
1005-
1006-
#rocq_ignore bi.emp_and' "The type class LeftId in Lean is not general enough"
1030+
@[rocq_alias bi.emp_and']
1031+
instance emp_and_biaffine [BI PROP] [BIAffine PROP] : LeftId (α := PROP) BiEntails emp and := ⟨emp_and⟩
10071032

10081033
@[rocq_alias bi.and_emp]
10091034
theorem and_emp [BI PROP] {P : PROP} [Affine P] : P ∧ emp ⊣⊢ P := and_comm.trans emp_and
1010-
1011-
#rocq_ignore bi.and_emp' "The type class RightId in Lean is not general enough"
1035+
@[rocq_alias bi.and_emp']
1036+
instance and_emp_biaffine [BI PROP] [BIAffine PROP] : RightId (α := PROP) BiEntails emp and := ⟨and_emp⟩
10121037

10131038
@[rocq_alias bi.emp_or]
10141039
theorem emp_or [BI PROP] {P : PROP} [Affine P] : emp ∨ P ⊣⊢ emp := ⟨or_elim .rfl affine, or_intro_l⟩
@@ -1033,12 +1058,14 @@ instance [BI PROP] [BIAffine PROP] (P : PROP) : Absorbing P where
10331058

10341059
@[rocq_alias bi.True_sep]
10351060
theorem true_sep [BI PROP] {P : PROP} [Absorbing P] : True ∗ P ⊣⊢ P := ⟨absorbing, true_sep_mpr⟩
1061+
instance [BI PROP] [BIAffine PROP] : LeftId (α := PROP) BiEntails iprop(True) sep := ⟨true_sep⟩
10361062

10371063
@[rocq_alias bi.True_sep']
10381064
theorem true_sep_flip [BI PROP] {P : PROP} [Absorbing P] : P ⊣⊢ True ∗ P := true_sep.symm
10391065

10401066
@[rocq_alias bi.sep_True]
10411067
theorem sep_true [BI PROP] {P : PROP} [Absorbing P] : P ∗ True ⊣⊢ P := sep_comm.trans true_sep
1068+
instance [BI PROP] [BIAffine PROP] : RightId (α := PROP) BiEntails iprop(True) sep := ⟨sep_true⟩
10421069

10431070
@[rocq_alias bi.sep_True']
10441071
theorem sep_true_flip [BI PROP] {P : PROP} [Absorbing P] : P ⊣⊢ P ∗ True :=

Iris/Iris/BI/DerivedLawsLater.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public import Iris.BI.Extensions
1010
public import Iris.BI.BI
1111
public import Iris.BI.DerivedLaws
1212
public import Iris.BI.BigOp.BigOp
13+
public import Iris.Std.Classes
1314
public import Iris.Std.Rewrite
1415
public import Iris.Std.TC
1516
public import Iris.Std.RocqPorting

Iris/Iris/BI/Instances.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public import Iris.BI.Classes
99
public import Iris.BI.DerivedLaws
1010
public import Iris.BI.Extensions
1111
public import Iris.BI.BI
12+
public import Iris.Std.Classes
1213

1314
@[expose] public section
1415

Iris/Iris/Examples/ClosedProofs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ example : True := by
6363
icases inv_alloc nroot ⊤ iprop(True) $$ [] with >#Hinv
6464
· itrivial
6565
imod inv_acc $$ Hinv with ⟨HP, Hcl⟩
66-
· rw [nclose_root]
66+
· rw [nclose_root]; exact subset_refl
6767
imod Hcl $$ HP with HP
6868
iapply fupd_mask_intro empty_subset
6969
iintro Hcl

Iris/Iris/HeapLang/PrimitiveLaws.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ theorem wp_resolve_strong {e : Exp} {p : ProphId} {w : Val} {pvs : List (Val ×
561561
· iapply HWPe; iexact Hp
562562
ihave HWPe := (show iprop(WP e @ s; E {{ v_e, ∃ pvs', proph p pvs' ∗
563563
∀ pvs'', ⌜pvs' = (v_e, w) :: pvs''⌝ -∗ proph p pvs'' -∗ Φ v_e }}) ⊢ _
564-
by rw [wp_unfold.to_eq]) $$ HWPe
565-
simp only [wp.pre, hne]
564+
by rw [wp_unfold.to_eq]; simp only [wp.pre, hne]; exact .rfl) $$ HWPe
566565
cases obs using List.reverseRec with
567566
| nil =>
568567
ihave Hσ_e : iprop(stateInterp σ₁ ns ([] ++ obs') nt) $$ [Hheap Hpmap]

Iris/Iris/Std.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module
22

3+
public import Iris.Std.Classes
34
public import Iris.Std.Expr
45
public import Iris.Std.HeapInstances
56
public import Iris.Std.Infinite

Iris/Iris/Std/Classes.lean

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/-
2+
Copyright (c) 2022 Lars König. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Lars König
5+
-/
6+
module
7+
8+
@[expose] public section
9+
10+
namespace Iris.Std
11+
12+
/-- Represents a binary relation with two arguments of the same type `α`. -/
13+
abbrev Relation (α : Type _) := α → α → Prop
14+
15+
/-- Require that a type `α` has a distinguished top element. -/
16+
class Top (α : Type u) where
17+
top : α
18+
export Top (top)
19+
20+
notation "⊤" => top
21+
22+
/-- Require that a binary function `f` on `α` is idempotent in a relation `R` on `α`. -/
23+
class Idempotent (R : Relation α) (f : α → α → α) where
24+
idem {x : α} : R (f x x) x
25+
export Idempotent (idem)
26+
27+
/-- Require that a binary function `f` from `β` to `α` is commutative in a relation `R` on `α`. -/
28+
class Commutative (R : Relation α) (f : β → β → α) where
29+
comm {x y : β} : R (f x y) (f y x)
30+
export Commutative (comm)
31+
32+
/-- Require that an element `i` of `α` is the left unit of a binary function `f` on `α` in a
33+
relation `R` on `α`. -/
34+
class LeftId (R : Relation α) (i : α) (f : α → α → α) where
35+
left_id {x : α} : R (f i x) x
36+
export LeftId (left_id)
37+
38+
/-- Require that an element `i` of `α` is the right unit of a binary function `f` on `α` in a
39+
relation `R` on `α`. -/
40+
class RightId (R : Relation α) (i : α) (f : α → α → α) where
41+
right_id {x : α} : R (f x i) x
42+
export RightId (right_id)
43+
44+
class LeftAbsorb (R : Relation α) (i : α) (f : α → α → α) where
45+
left_absorb {x : α} : R (f i x) i
46+
export LeftAbsorb (left_absorb)
47+
48+
class RightAbsorb (R : Relation α) (i : α) (f : α → α → α) where
49+
right_absorb {x : α} : R (f x i) i
50+
export RightAbsorb (right_absorb)
51+
52+
/-- Require that a binary function `f` on `α` is associative in a relation `R` on `α`. -/
53+
class Associative (R : Relation α) (f : α → α → α) where
54+
assoc {x y z : α} : R (f (f x y) z) (f x (f y z))
55+
export Associative (assoc)
56+
57+
/-- Require that a relation `S` on `α` is antisymmetrical with `R` as its equivalence relation. -/
58+
class Antisymmetric (R : Relation α) (S : outParam <| Relation α) where
59+
antisymm {x y : α} : (left : S x y) → (right : S y x) → R x y
60+
export Antisymmetric (antisymm)
61+
62+
class Disjoint (α : Type u) where
63+
disjoint : α -> α -> Prop
64+
export Disjoint (disjoint)
65+
infix:50 " ## " => Disjoint.disjoint
66+
67+
end Iris.Std

Iris/Iris/Std/CoPset.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Remy Seassau, Markus de Medeiros, Sergei Stepanenko
66
module
77

88
public import Iris.Std.Positives
9+
public import Iris.Std.Classes
910
public import Iris.Std.GenSets
1011
import Iris.Std.List
1112

@@ -219,6 +220,8 @@ instance : EmptyCollection CoPset where emptyCollection := CoPset.empty
219220

220221
def full : CoPset := ⟨CoPsetRaw.leaf true, rfl⟩
221222

223+
instance : Iris.Std.Top CoPset where top := CoPset.full
224+
222225
@[simp] def singleton (p : Pos) : CoPset := ⟨CoPsetRaw.Singleton p, coPsetSingleton_wf p⟩
223226

224227
instance : Singleton Pos CoPset where
@@ -252,9 +255,6 @@ theorem mem_empty {p : Pos} : p ∉ (∅ : CoPset) := by
252255
theorem mem_full {p : Pos} : p ∈ full := by
253256
simp only [Membership.mem, full, CoPsetRaw.ElemOf]
254257

255-
/-- `CoPset.full` is the top element in the type `CoPset`. -/
256-
notation "⊤" => CoPset.full
257-
258258
@[simp]
259259
theorem subseteq_top {X : CoPset} : X ⊆ ⊤ := λ _ _ => mem_full
260260

Iris/Iris/Std/GenMultiSets.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Haokun Li
55
-/
66
module
77

8+
public import Iris.Std.Classes
89
public import Iris.Std.GenSets
910
public import Batteries.Data.List.Perm
1011

0 commit comments

Comments
 (0)