@@ -30,6 +30,7 @@ open import Data.Product.Base as Prod
30
30
import Data.Product.Relation.Unary.All as Prod using (All)
31
31
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
32
32
open import Data.These.Base as These using (These; this; that; these)
33
+ open import Data.Fin.Properties using (toℕ-cast)
33
34
open import Function
34
35
open import Level using (Level)
35
36
open import Relation.Binary as B using (DecidableEquality)
@@ -759,6 +760,16 @@ length-take zero xs = refl
759
760
length-take (suc n) [] = refl
760
761
length-take (suc n) (x ∷ xs) = cong suc (length-take n xs)
761
762
763
+ take-suc : (xs : List A) (i : Fin (length xs)) → let m = toℕ i in
764
+ take (suc m) xs ≡ take m xs ∷ʳ lookup xs i
765
+ take-suc (x ∷ xs) zero = refl
766
+ take-suc (x ∷ xs) (suc i) = cong (x ∷_) (take-suc xs i)
767
+
768
+ take-suc-tabulate : ∀ {n} (f : Fin n → A) (i : Fin n) → let m = toℕ i in
769
+ take (suc m) (tabulate f) ≡ take m (tabulate f) ∷ʳ f i
770
+ take-suc-tabulate f i rewrite sym (toℕ-cast (sym (length-tabulate f)) i) | sym (lookup-tabulate f i)
771
+ = take-suc (tabulate f) (cast _ i)
772
+
762
773
-- If you take at least as many elements from a list as it has, you get the whole list.
763
774
take-all : (n : ℕ) (xs : List A) → n ≥ length xs → take n xs ≡ xs
764
775
take-all zero [] _ = refl
@@ -789,6 +800,16 @@ take++drop zero xs = refl
789
800
take++drop (suc n) [] = refl
790
801
take++drop (suc n) (x ∷ xs) = cong (x ∷_) (take++drop n xs)
791
802
803
+ drop-take-suc : (xs : List A) (i : Fin (length xs)) → let m = toℕ i in
804
+ drop m (take (suc m) xs) ≡ [ lookup xs i ]
805
+ drop-take-suc (x ∷ xs) zero = refl
806
+ drop-take-suc (x ∷ xs) (suc i) = drop-take-suc xs i
807
+
808
+ drop-take-suc-tabulate : ∀ {n} (f : Fin n → A) (i : Fin n) → let m = toℕ i in
809
+ drop m (take (suc m) (tabulate f)) ≡ [ f i ]
810
+ drop-take-suc-tabulate f i rewrite sym (toℕ-cast (sym (length-tabulate f)) i) | sym (lookup-tabulate f i)
811
+ = drop-take-suc (tabulate f) (cast _ i)
812
+
792
813
------------------------------------------------------------------------
793
814
-- splitAt
794
815
@@ -1093,6 +1114,8 @@ module _ {x y : A} where
1093
1114
∷ʳ-++ : ∀ (xs : List A) (a : A) (ys : List A) → xs ∷ʳ a ++ ys ≡ xs ++ a ∷ ys
1094
1115
∷ʳ-++ xs a ys = ++-assoc xs [ a ] ys
1095
1116
1117
+
1118
+
1096
1119
------------------------------------------------------------------------
1097
1120
-- DEPRECATED
1098
1121
------------------------------------------------------------------------
0 commit comments