mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-09-21 02:07:25 +03:00
Add list lemmas (#491)
This commit is contained in:
parent
78ecd8a9f1
commit
69612bf6bf
@ -1,5 +1,7 @@
|
||||
module Data.List
|
||||
|
||||
import Data.Nat
|
||||
|
||||
public export
|
||||
isNil : List a -> Bool
|
||||
isNil [] = True
|
||||
@ -620,3 +622,12 @@ revAppend (v :: vs) ns
|
||||
rewrite sym (revAppend vs ns) in
|
||||
rewrite appendAssociative (reverse ns) (reverse vs) [v] in
|
||||
Refl
|
||||
|
||||
export
|
||||
dropFusion : (n, m : Nat) -> (l : List t) -> drop n (drop m l) = drop (n+m) l
|
||||
dropFusion Z m l = Refl
|
||||
dropFusion (S n) Z l = rewrite plusZeroRightNeutral n in Refl
|
||||
dropFusion (S n) (S m) [] = Refl
|
||||
dropFusion (S n) (S m) (x::l) = rewrite plusAssociative n 1 m in
|
||||
rewrite plusCommutative n 1 in
|
||||
dropFusion (S n) m l
|
@ -76,3 +76,9 @@ indexElem : Nat -> (xs : List a) -> Maybe (x ** Elem x xs)
|
||||
indexElem _ [] = Nothing
|
||||
indexElem Z (y :: _) = Just (y ** Here)
|
||||
indexElem (S n) (_ :: ys) = map (\(x ** p) => (x ** There p)) (indexElem n ys)
|
||||
|
||||
||| Lift the membership proof to a mapped list
|
||||
export
|
||||
elemMap : (0 f : a -> b) -> Elem x xs -> Elem (f x) (map f xs)
|
||||
elemMap f Here = Here
|
||||
elemMap f (There el) = There $ elemMap f el
|
@ -78,3 +78,9 @@ export
|
||||
indexAll : Elem x xs -> All p xs -> p x
|
||||
indexAll Here (p::_ ) = p
|
||||
indexAll (There e) ( _::ps) = indexAll e ps
|
||||
|
||||
||| Modify the property given a pointwise function
|
||||
export
|
||||
mapProperty : (f : {0 x : a} -> p x -> q x) -> All p l -> All q l
|
||||
mapProperty f [] = []
|
||||
mapProperty f (p::pl) = f p :: mapProperty f pl
|
||||
|
Loading…
Reference in New Issue
Block a user