@@ -640,23 +640,23 @@ end Bit
640
640
section OfNatCoe
641
641
642
642
@[simp]
643
- theorem ofNat_eq_val (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a :=
643
+ theorem ofNat''_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a :=
644
644
rfl
645
- #align fin.of_nat_eq_coe Fin.ofNat_eq_val
645
+ #align fin.of_nat_eq_coe Fin.ofNat''_eq_cast
646
+
647
+ @[simp] lemma val_nat_cast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl
646
648
647
649
-- porting note: is this the right name for things involving `Nat.cast`?
648
650
/-- Converting an in-range number to `Fin (n + 1)` produces a result
649
651
whose value is the original number. -/
650
- theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := by
651
- rw [← ofNat_eq_val]
652
- exact Nat.mod_eq_of_lt h
652
+ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a :=
653
+ Nat.mod_eq_of_lt h
653
654
#align fin.coe_val_of_lt Fin.val_cast_of_lt
654
655
655
656
/-- Converting the value of a `Fin (n + 1)` to `Fin (n + 1)` results
656
657
in the same value. -/
657
- theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := by
658
- rw [Fin.eq_iff_veq]
659
- exact val_cast_of_lt a.isLt
658
+ theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a :=
659
+ ext <| val_cast_of_lt a.isLt
660
660
#align fin.coe_val_eq_self Fin.cast_val_eq_self
661
661
662
662
-- porting note: this is syntactically the same as `val_cast_of_lt`
@@ -665,9 +665,13 @@ theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a
665
665
-- porting note: this is syntactically the same as `cast_val_of_lt`
666
666
#align fin.coe_coe_eq_self Fin.cast_val_eq_self
667
667
668
- theorem cast_nat_eq_last (n) : (n : Fin (n + 1 )) = Fin.last n := by
669
- rw [← Fin.ofNat_eq_val, Fin.ofNat'', Fin.last]
670
- simp only [Nat.mod_eq_of_lt n.lt_succ_self]
668
+ @[simp] lemma nat_cast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp
669
+
670
+ @[simp] lemma nat_cast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by
671
+ simp [eq_iff_veq, Nat.dvd_iff_mod_eq_zero]
672
+
673
+ @[simp]
674
+ theorem cast_nat_eq_last (n) : (n : Fin (n + 1 )) = Fin.last n := by ext; simp
671
675
#align fin.coe_nat_eq_last Fin.cast_nat_eq_last
672
676
673
677
theorem le_val_last (i : Fin (n + 1 )) : i ≤ n := by
@@ -682,19 +686,13 @@ end OfNatCoe
682
686
#align fin.zero_ne_one Fin.zero_ne_one
683
687
684
688
@[simp]
685
- theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by
686
- constructor
687
- · intro h
688
- have := congr_arg ((↑) : Fin n → ℕ) h
689
- simp only [val_zero', val_one', @eq_comm _ 0 , ← Nat.dvd_iff_mod_eq_zero] at this
690
- exact eq_one_of_dvd_one this
691
- · rintro rfl
692
- rfl
693
- #align fin.zero_eq_one_iff Fin.zero_eq_one_iff
689
+ theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by
690
+ rw [← Nat.cast_one, nat_cast_eq_zero, Nat.dvd_one]
691
+ #align fin.one_eq_zero_iff Fin.one_eq_zero_iff
694
692
695
693
@[simp]
696
- theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by rw [eq_comm, zero_eq_one_iff ]
697
- #align fin.one_eq_zero_iff Fin.one_eq_zero_iff
694
+ theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by rw [eq_comm, one_eq_zero_iff ]
695
+ #align fin.zero_eq_one_iff Fin.zero_eq_one_iff
698
696
699
697
end Add
700
698
0 commit comments