Skip to content

Commit

Permalink
chore: fix namespacing in Std.Classes.Order (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Nov 19, 2023
1 parent 85f6436 commit 1d1197d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Std/Classes/Order.lean
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ theorem cmp_congr_right [TransCmp cmp] (yz : cmp y z = .eq) : cmp x y = cmp x z

end TransCmp

end Std

namespace Ordering

open Std

/-- Pull back a comparator by a function `f`, by applying the comparator to both arguments. -/
@[inline] def byKey (f : α → β) (cmp : β → β → Ordering) (a b : α) : Ordering := cmp (f a) (f b)

Expand All @@ -102,6 +108,8 @@ instance (f : α → β) (cmp : β → β → Ordering) [TransCmp cmp] : TransCm
instance (f : α → β) (cmp : β → β → Ordering) [TransCmp cmp] : TransCmp (byKey f cmp) where
le_trans h₁ h₂ := TransCmp.le_trans (α := β) h₁ h₂

end Ordering

@[simp] theorem ge_iff_le [LE α] {x y : α} : x ≥ y ↔ y ≤ x := Iff.rfl

@[simp] theorem gt_iff_lt [LT α] {x y : α} : x > y ↔ y < x := Iff.rfl
Expand Down
4 changes: 2 additions & 2 deletions Std/Data/RBMap/Alter.lean
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ so it uses the element linearly if `t` is unshared.
-/
def modify (t : RBMap α β cmp) (k : α) (f : β → β) : RBMap α β cmp :=
@RBSet.modifyP _ _ t (cmp k ·.1) (fun (a, b) => (a, f b))
(.of_eq fun _ => ⟨OrientedCmp.cmp_refl (cmp := byKey Prod.fst cmp)⟩)
(.of_eq fun _ => ⟨OrientedCmp.cmp_refl (cmp := Ordering.byKey Prod.fst cmp)⟩)

/-- Auxiliary definition for `alter`. -/
def alter.adapt (k : α) (f : Option β → Option β) : Option (α × β) → Option (α × β)
Expand Down Expand Up @@ -461,6 +461,6 @@ the ordering properties of the element, which would break the invariants.
cases t' <;> simp [alter.adapt, RBNode.root?] <;> split <;> intro h <;> cases h
· exact ⟨(t.2.out.1.zoom eq).2.2.2.toRootOrdered, ⟨⟩⟩
· refine ⟨(?a).RootOrdered_congr.2 (t.2.out.1.zoom eq).2.2.1.1, ?a⟩
exact ⟨OrientedCmp.cmp_refl (cmp := byKey Prod.fst cmp)⟩
exact ⟨OrientedCmp.cmp_refl (cmp := Ordering.byKey Prod.fst cmp)⟩

end RBMap
2 changes: 1 addition & 1 deletion Std/Data/RBMap/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ The `cmp` function is the comparator that will be used for performing searches;
it should satisfy the requirements of `TransCmp` for it to have sensible behavior.
-/
def RBMap (α : Type u) (β : Type v) (cmp : α → α → Ordering) : Type (max u v) :=
RBSet (α × β) (byKey Prod.fst cmp)
RBSet (α × β) (Ordering.byKey Prod.fst cmp)

/-- `O(1)`. Construct a new empty map. -/
@[inline] def mkRBMap (α : Type u) (β : Type v) (cmp : α → α → Ordering) : RBMap α β cmp :=
Expand Down
2 changes: 2 additions & 0 deletions Std/Data/RBMap/WF.lean
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ We extract this as a function so that `IsMonotone (mapSnd f)` can be an instance
-/
@[inline] def mapSnd (f : α → β → γ) := fun (a, b) => (a, f a b)

open Ordering (byKey)

instance (cmp : α → α → Ordering) (f : α → β → γ) :
IsMonotone (byKey Prod.fst cmp) (byKey Prod.fst cmp) (mapSnd f) where
lt_mono | ⟨h⟩ => ⟨@fun _ => @h {
Expand Down

0 comments on commit 1d1197d

Please sign in to comment.