include "logic/equality.ma".
include "higher_order_defs/functions.ma".
-inductive list (A:Set) : Set :=
+inductive list (A:Type) : Type :=
| nil: list A
| cons: A -> list A -> list A.
right associative with precedence 47
for @{'append $l1 $l2 }.
-interpretation "nil" 'nil = (cic:/matita/list/list.ind#xpointer(1/1/1) _).
+interpretation "nil" 'nil = (cic:/matita/list/list/list.ind#xpointer(1/1/1) _).
interpretation "cons" 'cons hd tl =
- (cic:/matita/list/list.ind#xpointer(1/1/2) _ hd tl).
+ (cic:/matita/list/list/list.ind#xpointer(1/1/2) _ hd tl).
(* theorem test_notation: [O; S O; S (S O)] = O :: S O :: S (S O) :: []. *)
theorem nil_cons:
- \forall A:Set.\forall l:list A.\forall a:A.
+ \forall A:Type.\forall l:list A.\forall a:A.
a::l <> [].
intros;
unfold Not;
[ nil => l2
| (cons hd tl) => hd :: append A tl l2 ].
-definition tail := \lambda A:Set. \lambda l: list A.
+definition tail := \lambda A:Type. \lambda l: list A.
match l with
[ nil => []
| (cons hd tl) => tl].
-interpretation "append" 'append l1 l2 = (cic:/matita/list/append.con _ l1 l2).
+interpretation "append" 'append l1 l2 = (cic:/matita/list/list/append.con _ l1 l2).
-theorem append_nil: \forall A:Set.\forall l:list A.l @ [] = l.
+theorem append_nil: \forall A:Type.\forall l:list A.l @ [] = l.
intros;
elim l;
[ reflexivity;
]
qed.
-theorem associative_append: \forall A:Set.associative (list A) (append A).
+theorem associative_append: \forall A:Type.associative (list A) (append A).
intros; unfold; intros;
elim x;
[ simplify;
qed.
theorem cons_append_commute:
- \forall A:Set.\forall l1,l2:list A.\forall a:A.
+ \forall A:Type.\forall l1,l2:list A.\forall a:A.
a :: (l1 @ l2) = (a :: l1) @ l2.
intros;
reflexivity;
qed.
-inductive permutation (A:Set) : list A -> list A -> Prop \def
+inductive permutation (A:Type) : list A -> list A -> Prop \def
| refl : \forall l:list A. permutation ? l l
| swap : \forall l:list A. \forall x,y:A.
permutation ? (x :: y :: l) (y :: x :: l)
(*
theorem nil_append_nil_both:
- \forall A:Set.\forall l1,l2:list A.
+ \forall A:Type.\forall l1,l2:list A.
l1 @ l2 = [] \to l1 = [] \land l2 = [].
*)
reflexivity.
qed.
*)
+
+let rec nth (A:Type) l d n on n ≝
+ match n with
+ [ O ⇒
+ match l with
+ [ nil ⇒ d
+ | cons (x : A) _ ⇒ x
+ ]
+ | S n' ⇒ nth A (tail ? l) d n'
+ ].