proof for interspersed list length

This commit is contained in:
rnhmjoj 2016-11-15 00:07:00 +01:00
parent fc3b3bd927
commit ccf95e0cb9
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C
2 changed files with 7 additions and 3 deletions

View File

@ -129,6 +129,10 @@ succ_right (SS n) m = cong SS (succ_right n m)
succ_left S n S m S (n :+ m) : (S n :+ m) succ_left S n S m S (n :+ m) : (S n :+ m)
succ_left n m = succ_right n m switch n m succ_left n m = succ_right n m switch n m
-- | Lemma
double S (S n) -> n :+ n : S (n :+ Pred n)
double (SS n) = gcastWith (succ_pred (SS n)) (sym (succ_right n (sPred n)))
-- | Relation between successor and addition -- | Relation between successor and addition
succ_plus S n (n :+ S Z) : S n succ_plus S n (n :+ S Z) : S n
succ_plus n = switch n SZ plus_right_id (SS n) succ_plus n = switch n SZ plus_right_id (SS n)

View File

@ -21,7 +21,7 @@ import Relation.Equality (gcastWith, cong, sym)
import Data.Nat import Data.Nat
import Data.Bool import Data.Bool
import Data.Char (Char) import Data.Char (Char)
import Data.Function (()) import Data.Function ((), ($))
import Data.TypeClass (Show, IsList, IsString, Eq) import Data.TypeClass (Show, IsList, IsString, Eq)
import Data.Singletons (SingI, sing) import Data.Singletons (SingI, sing)
@ -155,8 +155,8 @@ reverse (y :- ys) = gcastWith proof (reverse ys ⧺ (y :- Nil))
intersperse a Vec a n Vec a (n :+ Pred n) intersperse a Vec a n Vec a (n :+ Pred n)
intersperse _ Nil = Nil intersperse _ Nil = Nil
intersperse _ (x :- Nil) = x :- Nil intersperse _ (x :- Nil) = x :- Nil
intersperse s (x :- xs) = x :- s :- intersperse s xs intersperse s (x :- xs) = gcastWith (double n) (x :- s :- intersperse s xs)
where n = sLength (x :- xs)
-- | 'foldl' applied to a binary operator, a starting value -- | 'foldl' applied to a binary operator, a starting value
-- and a 'Vec' reduces the vector to a single value obtained -- and a 'Vec' reduces the vector to a single value obtained