Skip to content

Commit

Permalink
feat(data/fin): lemmas about ordering and cons (#13044)
Browse files Browse the repository at this point in the history
This marks a few extra facts `simp`, since the analogous facts are `simp` for `nat`.
  • Loading branch information
eric-wieser committed Mar 30, 2022
1 parent 644a848 commit 33a323c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion archive/imo/imo1994_q1.lean
Expand Up @@ -84,7 +84,7 @@ begin
simp at h hx ⊢,
rcases hx with ⟨i, ⟨hi, rfl⟩⟩,
have h1 : a i + a (fin.last m - k) ≤ n,
{ linarith only [h, a.monotone hi.2] },
{ linarith only [h, a.monotone hi] },
have h2 : a i + a (fin.last m - k) ∈ A := hadd _ (ha _) _ (ha _) h1,
rw [←mem_coe, ←range_order_emb_of_fin A hm, set.mem_range] at h2,
cases h2 with j hj,
Expand Down
7 changes: 5 additions & 2 deletions src/data/fin/basic.lean
Expand Up @@ -228,10 +228,12 @@ attribute [simp] val_zero
@[simp] lemma val_zero' (n) : (0 : fin (n+1)).val = 0 := rfl
@[simp] lemma mk_zero : (⟨0, nat.succ_pos'⟩ : fin (n + 1)) = (0 : fin _) := rfl

lemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1
@[simp] lemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1

lemma zero_lt_one : (0 : fin (n + 2)) < 1 := nat.zero_lt_one

@[simp] lemma not_lt_zero (a : fin n.succ) : ¬a < 0.

lemma pos_iff_ne_zero (a : fin (n+1)) : 0 < a ↔ a ≠ 0 :=
by rw [← coe_fin_lt, coe_zero, pos_iff_ne_zero, ne.def, ne.def, ext_iff, coe_zero]

Expand Down Expand Up @@ -516,6 +518,7 @@ section succ
@[simp] lemma coe_succ (j : fin n) : (j.succ : ℕ) = j + 1 :=
by cases j; simp [fin.succ]

@[simp]
lemma succ_pos (a : fin n) : (0 : fin (n + 1)) < a.succ := by simp [lt_iff_coe_lt_coe]

/-- `fin.succ` as an `order_embedding` -/
Expand Down Expand Up @@ -1268,7 +1271,7 @@ lemma succ_above_pos (p : fin (n + 2)) (i : fin (n + 1)) (h : 0 < i) : 0 < p.suc
begin
by_cases H : i.cast_succ < p,
{ simpa [succ_above_below _ _ H] using cast_succ_pos h },
{ simpa [succ_above_above _ _ (le_of_not_lt H)] using succ_pos _ },
{ simp [succ_above_above _ _ (le_of_not_lt H)] },
end

@[simp] lemma succ_above_cast_lt {x y : fin (n + 1)} (h : x < y)
Expand Down
14 changes: 14 additions & 0 deletions src/data/fin/tuple/basic.lean
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes
-/
import data.fin.basic
import order.pilex
/-!
# Operation on tuples
Expand Down Expand Up @@ -138,6 +139,19 @@ lemma cons_le [Π i, preorder (α i)] {x : α 0} {q : Π i, α i} {p : Π i : fi
cons x p ≤ q ↔ x ≤ q 0 ∧ p ≤ tail q :=
@le_cons _ (λ i, order_dual (α i)) _ x q p

lemma cons_le_cons [Π i, preorder (α i)] {x₀ y₀ : α 0} {x y : Π i : fin n, α (i.succ)} :
cons x₀ x ≤ cons y₀ y ↔ x₀ ≤ y₀ ∧ x ≤ y :=
forall_fin_succ.trans $ and_congr_right' $ by simp only [cons_succ, pi.le_def]

lemma pi_lex_lt_cons_cons {x₀ y₀ : α 0} {x y : Π i : fin n, α (i.succ)}
(s : Π {i : fin n.succ}, α i → α i → Prop) :
pi.lex (<) @s (fin.cons x₀ x) (fin.cons y₀ y) ↔
s x₀ y₀ ∨ x₀ = y₀ ∧ pi.lex (<) (λ i : fin n, @s i.succ) x y :=
begin
simp_rw [pi.lex, fin.exists_fin_succ, fin.cons_succ, fin.cons_zero, fin.forall_fin_succ],
simp [and_assoc, exists_and_distrib_left],
end

@[simp]
lemma range_cons {α : Type*} {n : ℕ} (x : α) (b : fin n → α) :
set.range (fin.cons x b : fin n.succ → α) = insert x (set.range b) :=
Expand Down

0 comments on commit 33a323c

Please sign in to comment.