X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Fmatita%2Flib%2Fbasics%2Flists%2Flist.ma;h=2ed7fcc868a9f1434e888f2f2400e365958ea130;hb=913512bbc9202f2109d53acd43dc8c0270b17184;hp=40839b28fcf26fcf3abfe016fcb9b873a9ce19a1;hpb=596896aaf7158f90a96c3220e4a8f0a420f593d6;p=helm.git diff --git a/matita/matita/lib/basics/lists/list.ma b/matita/matita/lib/basics/lists/list.ma index 40839b28f..2ed7fcc86 100644 --- a/matita/matita/lib/basics/lists/list.ma +++ b/matita/matita/lib/basics/lists/list.ma @@ -31,12 +31,12 @@ notation "hvbox(l1 break @ l2)" interpretation "nil" 'nil = (nil ?). interpretation "cons" 'cons hd tl = (cons ? hd tl). -definition not_nil: ∀A:Type[0].list A → Prop ≝ +definition is_nil: ∀A:Type[0].list A → Prop ≝ λA.λl.match l with [ nil ⇒ True | cons hd tl ⇒ False ]. theorem nil_cons: ∀A:Type[0].∀l:list A.∀a:A. a::l ≠ []. - #A #l #a @nmk #Heq (change with (not_nil ? (a::l))) >Heq // + #A #l #a @nmk #Heq (change with (is_nil ? (a::l))) >Heq // qed. (* @@ -65,12 +65,6 @@ theorem associative_append: ∀A.associative (list A) (append A). #A #l1 #l2 #l3 (elim l1) normalize // qed. -(* deleterio per auto -ntheorem cons_append_commute: - ∀A:Type.∀l1,l2:list A.∀a:A. - a :: (l1 @ l2) = (a :: l1) @ l2. -//; nqed. *) - theorem append_cons:∀A.∀a:A.∀l,l1.l@(a::l1)=(l@[a])@l1. #A #a #l #l1 >associative_append // qed. @@ -121,6 +115,46 @@ lemma filter_false : ∀A,l,a,p. p a = false → theorem eq_map : ∀A,B,f,g,l. (∀x.f x = g x) → map A B f l = map A B g l. #A #B #f #g #l #eqfg (elim l) normalize // qed. +(**************************** reverse *****************************) +let rec rev_append S (l1,l2:list S) on l1 ≝ + match l1 with + [ nil ⇒ l2 + | cons a tl ⇒ rev_append S tl (a::l2) + ] +. + +definition reverse ≝λS.λl.rev_append S l []. + +lemma reverse_single : ∀S,a. reverse S [a] = [a]. +// qed. + +lemma rev_append_def : ∀S,l1,l2. + rev_append S l1 l2 = (reverse S l1) @ l2 . +#S #l1 elim l1 normalize // +qed. + +lemma reverse_cons : ∀S,a,l. reverse S (a::l) = (reverse S l)@[a]. +#S #a #l whd in ⊢ (??%?); // +qed. + +lemma reverse_append: ∀S,l1,l2. + reverse S (l1 @ l2) = (reverse S l2)@(reverse S l1). +#S #l1 elim l1 [normalize // | #a #tl #Hind #l2 >reverse_cons +>reverse_cons // qed. + +lemma reverse_reverse : ∀S,l. reverse S (reverse S l) = l. +#S #l elim l // #a #tl #Hind >reverse_cons >reverse_append +normalize // qed. + +(* an elimination principle for lists working on the tail; +useful for strings *) +lemma list_elim_left: ∀S.∀P:list S → Prop. P (nil S) → +(∀a.∀tl.P tl → P (tl@[a])) → ∀l. P l. +#S #P #Pnil #Pstep #l <(reverse_reverse … l) +generalize in match (reverse S l); #l elim l // +#a #tl #H >reverse_cons @Pstep // +qed. + (**************************** length ******************************) let rec length (A:Type[0]) (l:list A) on l ≝ @@ -131,11 +165,19 @@ let rec length (A:Type[0]) (l:list A) on l ≝ notation "|M|" non associative with precedence 60 for @{'norm $M}. interpretation "norm" 'norm l = (length ? l). +lemma length_tail: ∀A,l. length ? (tail A l) = pred (length ? l). +#A #l elim l // +qed. + lemma length_append: ∀A.∀l1,l2:list A. |l1@l2| = |l1|+|l2|. #A #l1 elim l1 // normalize /2/ qed. +lemma length_map: ∀A,B,l.∀f:A→B. length ? (map ?? f l) = length ? l. +#A #B #l #f elim l // #a #tl #Hind normalize // +qed. + (****************************** nth ********************************) let rec nth n (A:Type[0]) (l:list A) (d:A) ≝ match n with