From cf54e5e5d205a87962bb59fcc07711c95af7a840 Mon Sep 17 00:00:00 2001 From: Markus Himmel Date: Thu, 27 Mar 2025 09:38:45 +0100 Subject: [PATCH] feat: basic `Fin` order lemmas (#7692) This PR upstreams a small number of ordering lemmas for `Fin` from mathlib. --- src/Init/Data/Fin/Lemmas.lean | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Init/Data/Fin/Lemmas.lean b/src/Init/Data/Fin/Lemmas.lean index c121a06af3..f63b58cd23 100644 --- a/src/Init/Data/Fin/Lemmas.lean +++ b/src/Init/Data/Fin/Lemmas.lean @@ -127,6 +127,33 @@ protected theorem ne_of_gt {a b : Fin n} (h : a < b) : b ≠ a := Fin.ne_of_val_ protected theorem le_of_lt {a b : Fin n} (h : a < b) : a ≤ b := Nat.le_of_lt h +protected theorem lt_of_le_of_lt {a b c : Fin n} : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt + +protected theorem lt_of_lt_of_le {a b c : Fin n} : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le + +protected theorem le_rfl {a : Fin n} : a ≤ a := Nat.le_refl _ + +protected theorem lt_iff_le_and_ne {a b : Fin n} : a < b ↔ a ≤ b ∧ a ≠ b := by + rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne + +protected theorem lt_or_lt_of_ne {a b : Fin n} (h : a ≠ b) : a < b ∨ b < a := + Nat.lt_or_lt_of_ne <| val_ne_iff.2 h + +protected theorem lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _ + +protected theorem le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm + +protected theorem le_of_eq {a b : Fin n} (hab : a = b) : a ≤ b := + Nat.le_of_eq <| congrArg val hab + +protected theorem ge_of_eq {a b : Fin n} (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm + +protected theorem eq_or_lt_of_le {a b : Fin n} : a ≤ b → a = b ∨ a < b := by + rw [Fin.ext_iff]; exact Nat.eq_or_lt_of_le + +protected theorem lt_or_eq_of_le {a b : Fin n} : a ≤ b → a < b ∨ a = b := by + rw [Fin.ext_iff]; exact Nat.lt_or_eq_of_le + theorem is_le (i : Fin (n + 1)) : i ≤ n := Nat.le_of_lt_succ i.is_lt @[simp] theorem is_le' {a : Fin n} : a ≤ n := Nat.le_of_lt a.is_lt