Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 07e46bc

Browse files
committed
feat(data/fin): iff on add or sub across last-0 break (#15916)
Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
1 parent 4ed5044 commit 07e46bc

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/data/fin/basic.lean

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,43 @@ begin
583583
{ rw [←succ_zero_eq_one, succ_lt_succ_iff], exact succ_pos a }
584584
end
585585

586+
@[simp] lemma add_one_lt_iff {n : ℕ} {k : fin (n + 2)} :
587+
k + 1 < k ↔ k = last _ :=
588+
begin
589+
simp only [lt_iff_coe_lt_coe, coe_add, coe_last, ext_iff],
590+
cases k with k hk,
591+
rcases (le_of_lt_succ hk).eq_or_lt with rfl|hk',
592+
{ simp },
593+
{ simp [hk'.ne, mod_eq_of_lt (succ_lt_succ hk'), le_succ _] }
594+
end
595+
596+
@[simp] lemma add_one_le_iff {n : ℕ} {k : fin (n + 1)} :
597+
k + 1 ≤ k ↔ k = last _ :=
598+
begin
599+
cases n,
600+
{ simp [subsingleton.elim (k + 1) k, subsingleton.elim (fin.last _) k] },
601+
rw [←not_iff_not, ←add_one_lt_iff, lt_iff_le_and_ne, not_and'],
602+
refine ⟨λ h _, h, λ h, h _⟩,
603+
rw [ne.def, ext_iff, coe_add_one],
604+
split_ifs with hk hk;
605+
simp [hk, eq_comm],
606+
end
607+
608+
@[simp] lemma last_le_iff {n : ℕ} {k : fin (n + 1)} :
609+
last n ≤ k ↔ k = last n :=
610+
top_le_iff
611+
612+
@[simp] lemma lt_add_one_iff {n : ℕ} {k : fin (n + 1)} :
613+
k < k + 1 ↔ k < last n :=
614+
begin
615+
rw ←not_iff_not,
616+
simp
617+
end
618+
619+
@[simp] lemma le_zero_iff {n : ℕ} {k : fin (n + 1)} :
620+
k ≤ 0 ↔ k = 0 :=
621+
le_bot_iff
622+
586623
lemma succ_succ_ne_one (a : fin n) : fin.succ (fin.succ a) ≠ 1 := ne_of_gt (one_lt_succ_succ a)
587624

588625
/-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into. -/
@@ -1294,6 +1331,34 @@ begin
12941331
nat.mod_eq_of_lt (tsub_lt_self (nat.succ_pos _) (tsub_pos_of_lt h)), h] }
12951332
end
12961333

1334+
@[simp] lemma lt_sub_one_iff {n : ℕ} {k : fin (n + 2)} :
1335+
k < k - 1 ↔ k = 0 :=
1336+
begin
1337+
rcases k with ⟨(_|k), hk⟩,
1338+
simp [lt_iff_coe_lt_coe],
1339+
have : (k + 1 + (n + 1)) % (n + 2) = k % (n + 2),
1340+
{ rw [add_right_comm, add_assoc, add_mod_right] },
1341+
simp [lt_iff_coe_lt_coe, ext_iff, fin.coe_sub, succ_eq_add_one, this,
1342+
mod_eq_of_lt ((lt_succ_self _).trans hk)]
1343+
end
1344+
1345+
@[simp] lemma le_sub_one_iff {n : ℕ} {k : fin (n + 1)} :
1346+
k ≤ k - 1 ↔ k = 0 :=
1347+
begin
1348+
cases n,
1349+
{ simp [subsingleton.elim (k - 1) k, subsingleton.elim 0 k] },
1350+
rw [←lt_sub_one_iff, le_iff_lt_or_eq, lt_sub_one_iff, or_iff_left_iff_imp, eq_comm,
1351+
sub_eq_iff_eq_add],
1352+
simp
1353+
end
1354+
1355+
lemma sub_one_lt_iff {n : ℕ} {k : fin (n + 1)} :
1356+
k - 1 < k ↔ 0 < k :=
1357+
begin
1358+
rw ←not_iff_not,
1359+
simp
1360+
end
1361+
12971362
/-- By sending `x` to `last n - x`, `fin n` is order-equivalent to its `order_dual`. -/
12981363
def _root_.order_iso.fin_equiv : ∀ {n}, (fin n)ᵒᵈ ≃o fin n
12991364
| 0 := ⟨⟨elim0, elim0, elim0, elim0⟩, elim0⟩

0 commit comments

Comments
 (0)