Skip to content

Commit

Permalink
chore: DecidableRel allows a heterogeneous relation (#6341)
Browse files Browse the repository at this point in the history
This PR generalizes `DecidableRel` to allow a heterogeneous relation.
  • Loading branch information
kim-em authored Dec 11, 2024
1 parent 19fb1fb commit 8709ca3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Init/Data/Nat/Dvd.lean
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ theorem dvd_of_mod_eq_zero {m n : Nat} (H : n % m = 0) : m ∣ n := by
theorem dvd_iff_mod_eq_zero {m n : Nat} : m ∣ n ↔ n % m = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩

instance decidable_dvd : @DecidableRel Nat (·∣·) :=
instance decidable_dvd : @DecidableRel Nat Nat (·∣·) :=
fun _ _ => decidable_of_decidable_of_iff dvd_iff_mod_eq_zero.symm

theorem emod_pos_of_not_dvd {a b : Nat} (h : ¬ a ∣ b) : 0 < b % a := by
Expand Down
4 changes: 2 additions & 2 deletions src/Init/Data/Option/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ This is similar to `<|>`/`orElse`, but it is strict in the second argument. -/
| some a, _ => some a
| none, b => b

@[inline] protected def lt (r : α → αProp) : Option α → Option αProp
@[inline] protected def lt (r : α → βProp) : Option α → Option βProp
| none, some _ => True
| some x, some y => r x y
| _, _ => False

instance (r : α → αProp) [s : DecidableRel r] : DecidableRel (Option.lt r)
instance (r : α → βProp) [s : DecidableRel r] : DecidableRel (Option.lt r)
| none, some _ => isTrue trivial
| some x, some y => s x y
| some _, none => isFalse not_false
Expand Down
4 changes: 2 additions & 2 deletions src/Init/Prelude.lean
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ abbrev DecidablePred {α : Sort u} (r : α → Prop) :=
(a : α) → Decidable (r a)

/-- A decidable relation. See `Decidable`. -/
abbrev DecidableRel {α : Sort u} (r : α → αProp) :=
(a b : α) → Decidable (r a b)
abbrev DecidableRel {α : Sort u} {β : Sort v} (r : α → βProp) :=
(a : α) → (b : β) → Decidable (r a b)

/--
Asserts that `α` has decidable equality, that is, `a = b` is decidable
Expand Down
4 changes: 2 additions & 2 deletions src/lake/Lake/Util/Log.lean
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ instance : OfNat Log.Pos (nat_lit 0) := ⟨⟨0⟩⟩
instance : Ord Log.Pos := ⟨(compare ·.val ·.val)⟩
instance : LT Log.Pos := ⟨(·.val < ·.val)⟩
instance : DecidableRel (LT.lt (α := Log.Pos)) :=
inferInstanceAs (DecidableRel (α := Log.Pos) (·.val < ·.val))
inferInstanceAs (DecidableRel (α := Log.Pos) (β := Log.Pos) (·.val < ·.val))
instance : LE Log.Pos := ⟨(·.val ≤ ·.val)⟩
instance : DecidableRel (LE.le (α := Log.Pos)) :=
inferInstanceAs (DecidableRel (α := Log.Pos) (·.val ≤ ·.val))
inferInstanceAs (DecidableRel (α := Log.Pos) (β := Log.Pos) (·.val ≤ ·.val))
instance : Min Log.Pos := minOfLe
instance : Max Log.Pos := maxOfLe

Expand Down

0 comments on commit 8709ca3

Please sign in to comment.