-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add List.finRange and Array.finRange
Harmonize with Mathlib, renaming Fin.list to List.finRange and Fin.enum to Array.finRange.
- Loading branch information
Showing
9 changed files
with
140 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import Batteries.Data.Fin.Basic | ||
import Batteries.Data.Fin.Fold | ||
import Batteries.Data.Fin.Lemmas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/- | ||
Copyright (c) 2024 François G. Dorais. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: François G. Dorais | ||
-/ | ||
import Batteries.Data.List.FinRange | ||
|
||
namespace Fin | ||
|
||
theorem foldlM_eq_foldlM_finRange [Monad m] (f : α → Fin n → m α) (x) : | ||
foldlM n f x = (List.finRange n).foldlM f x := by | ||
induction n generalizing x with | ||
| zero => simp | ||
| succ n ih => | ||
rw [foldlM_succ, List.finRange_succ, List.foldlM_cons] | ||
congr; funext | ||
rw [List.foldlM_map, ih] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias foldlM_eq_foldlM_list := foldlM_eq_foldlM_finRange | ||
|
||
theorem foldrM_eq_foldrM_finRange [Monad m] [LawfulMonad m] (f : Fin n → α → m α) (x) : | ||
foldrM n f x = (List.finRange n).foldrM f x := by | ||
induction n with | ||
| zero => simp | ||
| succ n ih => rw [foldrM_succ, ih, List.finRange_succ, List.foldrM_cons, List.foldrM_map] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias foldrM_eq_foldrM_list := foldrM_eq_foldrM_finRange | ||
|
||
theorem foldl_eq_foldl_finRange (f : α → Fin n → α) (x) : | ||
foldl n f x = (List.finRange n).foldl f x := by | ||
induction n generalizing x with | ||
| zero => rw [foldl_zero, List.finRange_zero, List.foldl_nil] | ||
| succ n ih => rw [foldl_succ, ih, List.finRange_succ, List.foldl_cons, List.foldl_map] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias foldl_eq_foldl_list := foldl_eq_foldl_finRange | ||
|
||
theorem foldr_eq_foldr_finRange (f : Fin n → α → α) (x) : | ||
foldr n f x = (List.finRange n).foldr f x := by | ||
induction n with | ||
| zero => rw [foldr_zero, List.finRange_zero, List.foldr_nil] | ||
| succ n ih => rw [foldr_succ, ih, List.finRange_succ, List.foldr_cons, List.foldr_map] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias foldr_eq_foldr_list := foldr_eq_foldr_finRange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/- | ||
Copyright (c) 2024 François G. Dorais. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: François G. Dorais | ||
-/ | ||
import Batteries.Data.List.OfFn | ||
|
||
namespace List | ||
|
||
@[simp] theorem length_finRange (n) : (List.finRange n).length = n := by | ||
simp [List.finRange] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias length_list := length_finRange | ||
|
||
@[simp] theorem getElem_finRange (i : Nat) (h : i < (List.finRange n).length) : | ||
(finRange n)[i] = Fin.cast (length_finRange n) ⟨i, h⟩ := by | ||
simp [List.finRange] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias getElem_list := getElem_finRange | ||
|
||
@[simp] theorem finRange_zero : finRange 0 = [] := by simp [finRange, ofFn] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias list_zero := finRange_zero | ||
|
||
theorem finRange_succ (n) : finRange (n+1) = 0 :: (finRange n).map Fin.succ := by | ||
apply List.ext_getElem; simp; intro i; cases i <;> simp | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias list_succ := finRange_succ | ||
|
||
theorem finRange_succ_last (n) : | ||
finRange (n+1) = (finRange n).map Fin.castSucc ++ [Fin.last n] := by | ||
apply List.ext_getElem | ||
· simp | ||
· intros | ||
simp only [List.finRange, List.getElem_ofFn, getElem_append, length_map, length_ofFn, | ||
getElem_map, Fin.castSucc_mk, getElem_singleton] | ||
split | ||
· rfl | ||
· next h => exact Fin.eq_last_of_not_lt h | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias list_succ_last := finRange_succ_last | ||
|
||
theorem finRange_reverse (n) : (finRange n).reverse = (finRange n).map Fin.rev := by | ||
induction n with | ||
| zero => simp | ||
| succ n ih => | ||
conv => lhs; rw [finRange_succ_last] | ||
conv => rhs; rw [finRange_succ] | ||
rw [reverse_append, reverse_cons, reverse_nil, nil_append, singleton_append, ← map_reverse, | ||
map_cons, ih, map_map, map_map] | ||
congr; funext | ||
simp [Fin.rev_succ] | ||
|
||
@[deprecated (since := "2024-11-19")] | ||
alias list_reverse := finRange_reverse |