Skip to content

Commit 188fc54

Browse files
committed
feat: pushing Lattice and predecessors through Equiv (leanprover-community#37605)
The point is to transfer as cheaply as possible instances over to type synonyms. Note that we already have these for most of the algebraic hierarchy even when they "generalise" from an equiv to a structure-preserving injective function (note that the equiv needn't be structure-preserving, precisely because said structure needn't exist already). Co-authored-by: Parcly Taxel <reddeloostw@gmail.com>
1 parent 8ed3639 commit 188fc54

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Mathlib/Logic/Equiv/Defs.lean

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ def finTwoEquiv : Fin 2 ≃ Bool where
896896
right_inv b := by grind
897897

898898
namespace Equiv
899+
899900
variable {α β : Type*}
900901

901902
/-- The left summand of `α ⊕ β` is equivalent to `α`. -/
@@ -912,4 +913,46 @@ def sumIsRight : {x : α ⊕ β // x.isRight} ≃ β where
912913
invFun b := ⟨.inr b, Sum.isRight_inr⟩
913914
left_inv | ⟨.inr _b, _⟩ => rfl
914915

916+
variable (e : α ≃ β)
917+
918+
/-- Transfer `LE` across an `Equiv`. -/
919+
protected abbrev le [LE β] : LE α where
920+
le a b := e a ≤ e b
921+
922+
lemma le_def [LE β] (a b : α) :
923+
letI := e.le
924+
e a ≤ e b ↔ a ≤ b := Iff.rfl
925+
926+
/-- Transfer `LT` across an `Equiv`. -/
927+
protected abbrev lt [LT β] : LT α where
928+
lt a b := e a < e b
929+
930+
lemma lt_def [LT β] (a b : α) :
931+
letI := e.lt
932+
e a < e b ↔ a < b := Iff.rfl
933+
934+
/-- Transfer `Max` across an `Equiv`. -/
935+
protected abbrev max [Max β] : Max α where
936+
max a b := e.symm (max (e a) (e b))
937+
938+
lemma max_def [Max β] (a b : α) :
939+
letI := e.max
940+
max a b = e.symm (max (e a) (e b)) := rfl
941+
942+
/-- Transfer `Min` across an `Equiv`. -/
943+
protected abbrev min [Min β] : Min α where
944+
min a b := e.symm (min (e a) (e b))
945+
946+
lemma min_def [Min β] (a b : α) :
947+
letI := e.min
948+
min a b = e.symm (min (e a) (e b)) := rfl
949+
950+
/-- Transfer `Ord` across an `Equiv`. -/
951+
protected abbrev ord [Ord β] : Ord α where
952+
compare a b := compare (e a) (e b)
953+
954+
lemma ord_def [Ord β] (a b : α) :
955+
letI := e.ord
956+
compare a b = compare (e a) (e b) := rfl
957+
915958
end Equiv

Mathlib/Order/Lattice.lean

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,54 @@ protected abbrev Subtype.distribLattice [DistribLattice α] {P : α → Prop}
992992
letI := Subtype.lattice Psup Pinf
993993
Subtype.coe_injective.distribLattice _ coe_le_coe coe_lt_coe (coe_sup Psup) (coe_inf Pinf)
994994

995+
namespace Equiv
996+
997+
variable (e : α ≃ β)
998+
999+
/-- Transfer `Preorder` across an `Equiv`. -/
1000+
protected abbrev preorder [Preorder β] : Preorder α := by
1001+
let le := e.le
1002+
let lt := e.lt
1003+
apply Function.Injective.preorder e <;> intros <;> rfl
1004+
1005+
/-- Transfer `PartialOrder` across an `Equiv`. -/
1006+
protected abbrev partialOrder [PartialOrder β] : PartialOrder α := by
1007+
let preorder := e.preorder
1008+
apply e.injective.partialOrder <;> intros <;> rfl
1009+
1010+
/-- Transfer `LinearOrder` across an `Equiv`. -/
1011+
protected abbrev linearOrder [LinearOrder β] [DecidableEq α] : LinearOrder α := by
1012+
let max := e.max
1013+
let min := e.min
1014+
let preorder := e.preorder
1015+
let compare := e.ord
1016+
apply e.injective.linearOrder <;> intros <;> first | rfl | exact e.apply_symm_apply _
1017+
1018+
/-- Transfer `SemilatticeSup` across an `Equiv`. -/
1019+
protected abbrev semilatticeSup [SemilatticeSup β] : SemilatticeSup α := by
1020+
let max := e.max
1021+
let partialOrder := e.partialOrder
1022+
apply e.injective.semilatticeSup <;> intros <;> first | rfl | exact e.apply_symm_apply _
1023+
1024+
/-- Transfer `SemilatticeInf` across an `Equiv`. -/
1025+
protected abbrev semilatticeInf [SemilatticeInf β] : SemilatticeInf α := by
1026+
let min := e.min
1027+
let partialOrder := e.partialOrder
1028+
apply e.injective.semilatticeInf <;> intros <;> first | rfl | exact e.apply_symm_apply _
1029+
1030+
/-- Transfer `Lattice` across an `Equiv`. -/
1031+
protected abbrev lattice [Lattice β] : Lattice α := by
1032+
let semilatticeSup := e.semilatticeSup
1033+
let semilatticeInf := e.semilatticeInf
1034+
apply e.injective.lattice <;> intros <;> first | rfl | exact e.apply_symm_apply _
1035+
1036+
/-- Transfer `DistribLattice` across an `Equiv`. -/
1037+
protected abbrev distribLattice [DistribLattice β] : DistribLattice α := by
1038+
let lattice := e.lattice
1039+
apply e.injective.distribLattice <;> intros <;> first | rfl | exact e.apply_symm_apply _
1040+
1041+
end Equiv
1042+
9951043
end lift
9961044

9971045
namespace ULift

0 commit comments

Comments
 (0)