3 Section Arith_Functions.
5 Section head_tail_append.
9 Definition hd: (List S) -> (List S) := (listrec S [_](List S) (empty ?) [_;_](fr ? (empty ?))).
11 Definition hde: S -> (List S) -> S := [a](listrec S [_]S a [_;_;a]a).
13 Definition tl: (List S) -> (List S) := (listrec S [_](List S) (empty ?) [v;_;_]v).
15 Definition app: (List S) -> (List S) -> (List S) := [v](listrec S [_](List S) v [_;p;a](fr S p a)).
17 Definition app_three: (List S) -> (List S) -> (List S) -> (List S) := [v,w](app (app v w)).
19 Definition bs_app: (ListS S) -> N -> (List S) := (bs_iter (List S) (empty S) app).
21 Definition rbs_app: (ListS S)->N->(List S) := (rbs_iter (List S) (empty S) app).
23 Definition LIn: S -> (List S) -> Set := [a;l](LEx (List S) [v](LEx (List S) [w](Id (List S) (app (fr S v a) w) l))).
29 Variable S:Set; n:N; v:(List S).
31 Definition lskip: N -> (List S) -> (List S) := (natrec [_](List S)->(List S) [w]w [_;p;w](p (tl ? w))).
33 Definition lfirst: N -> (List S) -> (List S) := (natrec [_](List S)->(List S) [_](empty S) [_;p;w](app ? (p (tl ? w)) (hd ? w))).
35 Definition lslice: N -> N -> (List S) -> (List S) := [m;n;v](lfirst n (lskip m v)).
37 Definition lix: N -> (List S) -> (List S) := [n;v](hd S (lskip n v)).
39 Definition lixe: S -> N -> (List S) -> S := [a;n;v](hde S a (lskip n v)).
41 Definition llen: (List S) -> N := (listrec S [_]N zero [_;p;_](succ p)).
47 Definition pred: N -> N := (tl One).
49 Definition add: N -> N -> N := (app One).
51 Definition add_three: N -> N -> N -> N := (app_three One).
53 Definition bs_add: NS -> N -> N := (bs_app One).
55 Definition rbs_add:NS->N->N := (rbs_app One).
57 Definition sub: N -> N -> N := [m;n](lskip One n m).
59 Definition sub_t: N -> N -> N -> N := [m,n](sub (sub m n)).
61 Definition absv: N -> N -> N := [m;n](plus (minus m n) (minus n m)).
71 Theorem bs_app_fold: (n:N; S:Set; ls:(ListS S); P:(List S)->Set) (P (bs_app S ls n)) -> (P (bs_iter (List S) (empty S) (app S) ls n)).
76 Theorem pred_fold: (n:N; P:N->Set) (P (pred n)) -> (P (tl One n)).
81 Theorem add_fold: (m,n:N; P:N->Set) (P (add m n)) -> (P (app One m n)).
83 Apply (id_repl N (app One m n) (add m n)).
88 Theorem bs_add_fold: (n:N; ns:NS; P:N->Set) (P (bs_add ns n)) -> (P (bs_app One ns n)).
97 Section Arith_Results.
99 Section head_tail_results.
101 Theorem fr_ini1: (S:Set; a,b:S; v,w:(List S)) (Id (List S) (fr S v a) (fr S w b)) -> (Id (List S) v w).
103 MApply '(id_repl (List S) v (tl S (fr S v a))).
104 MApply '(id_repl (List S) w (tl S (fr S w b))).
105 MApply '(id_comp (List S)).
108 Theorem fr_ini2: (S:Set; v,w:(List S); a,b:S) (Id (List S) (fr S v a) (fr S w b)) -> (Id S a b).
110 MApply '(id_repl S a (hde S a (fr S v a))).
111 MApply '(id_repl S b (hde S a (fr S w b))).
112 MApply '(id_comp (List S)).
115 Theorem hd_hde_id: (S:Set; a:S; v:(List S)) (GT (llen S v) zero) -> (Id (List S) (hd S v) (fr S (empty S) (hde S a v))).
118 MApply '(gt_false zero).
121 Theorem tl_len: (S:Set; v:(List S)) (Id N (llen S (tl S v)) (pred (llen S v))).
126 Theorem app_empty: (S:Set; v:(List S)) (Id (List S) (app S (empty S) v) v).
129 MApply '(id_comp (List S) (List S) [v:?](fr S v s)).
132 Theorem app_ass: (S:Set; u,v,w:(List S)) (Id (List S) (app S (app S u v) w) (app S u (app S v w))).
135 MApply '(id_comp (List S) (List S) [v:?](fr S v y)).
138 Theorem lin_i: (S:Set; v,w,l:(List S); a:S) (Id (List S) (app S (fr S v a) w) l) -> (LIn S a l).
141 MApply '(lex_i (List S) v).
142 MApply '(lex_i (List S) w).
145 Theorem lin_e: (S:Set; a:S; l:(List S); P:Set) (LIn S a l) -> ((v,w:(List S)) (Id (List S) (app S (fr S v a) w) l) -> P) -> P.
152 Theorem lin_fr_i: (S:Set; a,b:S; l:(List S)) (LOr (LIn S a l) (Id S a b)) -> (LIn S a (fr S l b)).
154 MElim 'H '(when (LIn S a l) (Id S a b)).
155 MApply '(lin_e S a l).
156 MApply '(id_repl (List S) l (app S (fr S v a) w)).
157 MApply '(lin_i S v (fr S w b)).
158 MApply '(id_repl S b a).
159 MApply '(lin_i S l (empty S)).
162 End head_tail_results.
164 Section slicing_results.
166 Theorem lskip_empty: (S:Set; n:N) (Id (List S) (lskip S n (empty S)) (empty S)).
171 Theorem lskip_tl: (S:Set; n:N; v:(List S)) (Id (List S) (lskip S n (tl S v)) (tl S (lskip S n v))).
175 (MApply '(id_repl ? (lskip S n0 (empty S)) (empty S)); MApply 'id_comm).
180 Theorem lixe_empty: (n:N; S:Set; a:S) (Id S (lixe S a n (empty S)) a).
185 Theorem lixe_app_v: (S:Set; a,b:S; w,v:(List S); n:N) (GT (llen S v) n) -> (Id S (lixe S a n (app S w v)) (lixe S b n v)).
187 (Elim v using listrec; MSimpl).
189 MApply '(gt_false n).
192 (Unfold lixe; Simpl).
193 Fold (lixe S a n0 (app S w l)) (lixe S b n0 l). (**)
197 Theorem lixe_le: (S:Set; a:S; v:(List S); n:N) (LE (llen S v) n) -> (Id S (lixe S a n v) a).
199 (Elim v using listrec; Simpl).
205 MApply '(le_false (succ (llen S l))).
206 (Unfold lixe; Simpl).
207 Fold (lixe S a n0 l). (**)
211 Theorem lslice_lix: (S:Set; k:N; v:(List S)) (Id (List S) (lslice S k one v) (lix S k v)).
213 Unfold lslice lfirst.
220 Section arithmetics_results.
222 Theorem succ_ini: (m,n:N) (Id N (succ m) (succ n)) -> (Id N m n).
224 MApply '(fr_ini1 One tt tt).
227 Theorem sub_succ: (m,n:N) (LE m n) ->
228 (Id N (sub (succ n) m) (succ (sub n m))).
235 MApply '(le_false m').
239 Theorem succ_pred: (n:N) (GT n zero) -> (Id N (succ (pred n)) n).
242 MApply '(gt_false zero).
245 Theorem add_zero: (n:N) (Id N (add zero n) n).
251 Theorem add_ass: (l,m,n:N) (Id N (add (add l m) n) (add l (add m n))).
257 Theorem add_succ: (m,n:N) (Id N (add (succ m) n) (succ (add m n))).
259 (MElim 'n 'natrec; Apply succ_fold). (**)
263 Theorem add_comm: (m,n:N) (Id N (add m n) (add n m)).
267 MApply '(id_trans ? (succ (add n n0))).
269 Apply succ_fold. (**)
274 Theorem add_pred: (n,m:N) (GT n zero) -> (Id N (succ (add (pred n) m)) (add n m)).
278 (Apply succ_fold; Apply succ_fold). (**)
283 Theorem le_comp_pred: (m,n:N) (LE m n) -> (LE (pred m) (pred n)).
290 MApply '(le_false m').
293 Theorem le_add: (m,n:N) (LE m (add m n)).
297 MApply '(le_trans (add m n0)).
298 Apply succ_fold. (**)
302 Theorem le_comp_add: (m1,m2,n:N) (LE m1 m2) -> (LE (add m1 n) (add m2 n)).
305 (Apply succ_fold; Apply succ_fold). (**)
306 MApply 'le_comp_succ.
310 Theorem le_comp_add2: (m,n1,n2:N) (LE n1 n2) -> (LE (add m n1) (add m n2)).
312 MApply '(id_repl N (add m n1) (add n1 m)).
314 MApply '(id_repl N (add m n2) (add n2 m)).
319 Theorem gt_comp_add2: (m,n1,n2:N) (GT n1 n2) -> (GT (add m n1) (add m n2)).
322 MApply '(id_repl N (succ (add m n2)) (add m (succ n2))).
323 MApply 'le_comp_add2.
327 Theorem le_comp_sub: (n,m1,m2:N) (LE m1 m2) -> (LE (sub m1 n) (sub m2 n)).
330 MApply '(H (pred m1) (pred m2)).
331 MApply 'le_comp_pred.
334 Theorem gt_comp_sub: (m1,m2,n:N) (LE n m2) -> (GT m1 m2) -> (GT (sub m1 n) (sub m2 n)).
337 MApply '(id_repl N (succ (sub m2 n)) (sub (succ m2) n)).
343 Theorem le_zero_add: (m,n:N) (LE (add n m) zero) -> (Id N n zero).
346 MApply '(le_trans (add n m)).
350 Theorem sub_pred_l: (n,m:N) (Id N (sub (pred m) n) (pred (sub m n))).
356 Theorem sub_zero: (n,m:N) (LE m n) -> (Id N (sub m n) zero).
372 Theorem succ_pred_e: (m,n:N) (Id N m (succ n)) -> (Id N (pred m) n).
382 Theorem add_sub_e: (n,m2,m1:N) (Id N m1 (add m2 n)) -> (Id N (sub m1 m2) n).
388 MApply '(id_repl N m2 m1).
391 Elim m2 using natrec.
394 MApply '(id_repl N (succ n') (add zero (succ n'))).
398 MApply 'pred_fold. (**)
399 MApply '(H1 (pred m1)).
401 Fold (succ (add (succ m2') n')) in H2. (**)
402 MApply '(id_repl N (add m2' (succ n')) (add (succ m2') n')).
403 MApply '(add_succ m2' n').
407 Theorem sub_add: (m,n:N) (Id N (sub (add m n) n) m).
413 Theorem gt_add_di: (a,m,n:N) (GT (add m n) a) ->
414 (LOr (GT m a) (GT n (sub a m))).
416 MApply '(lor_e (LE m a) (GT m a)).
417 MCut '(GT n (sub a m)).
418 MApply '(id_repl N n (sub (add n m) m)).
421 MApply '(id_repl N (add n m) (add m n)).
428 Theorem app_llen: (S:Set; w,v:(List S)) (Id N (llen S (app S w v)) (add (llen S w) (llen S v))).
431 Apply succ_fold. (**)
435 Theorem bsapp_llen: (S:Set; vs:N->(List S); n:N) (Id N (llen S (bs_app S vs n)) (bs_add [n](llen S (vs n)) n)).
438 MApply '(id_repl ? (bs_add [n:N](llen S (vs n)) n0) (llen S (bs_app S vs n0))).
442 Theorem rbsapp_llen: (S:Set; vs:N->(List S); n:N) (Id N (llen S (rbs_app S vs n)) (rbs_add [n](llen S (vs n)) n)).
444 Unfold rbs_add rbs_app rbs_iter.
447 Apply bs_add_fold. (**)
451 Theorem lskip_llen: (S:Set; v:(List S); n:N) (Id N (llen S (lskip S n v)) (sub (llen S v) n)).
454 Fold (pred (llen S v)). (**)
455 MApply '(id_trans ? (pred (llen S (lskip S n0 v)))).
456 MApply '(id_repl ? (lskip S n0 (tl S v)) (tl S (lskip S n0 v))).
457 (MApply 'id_comm; MApply 'lskip_tl).
459 MApply '(id_trans ? (pred (sub (llen S v) n0))).
461 (MApply 'id_comm; MApply 'sub_pred_l).
464 Theorem lskip_le: (S:Set; v:(List S); n:N) (LE (llen S v) n) -> (Id N (llen S (lskip S n v)) zero).
466 MApply '(id_trans ? (sub (llen S v) n)).
471 Theorem lslice_succ_r: (S:Set; v:(List S); k,n:N) (Id (List S) (lslice S k (succ n) v) (app S (lslice S (succ k) n v) (lix S k v))).
473 (Unfold lslice lix; MSimpl).
474 MApply '(id_repl ? (tl S (lskip S k v)) (lskip S k (tl S v))).
478 Theorem lslice_succ_l: (S:Set; v:(List S); n,k:N) (Id (List S) (lslice S k (succ n) v) (app S (lix S (add k n) v) (lslice S k n v))).
482 MApply '(id_repl ? (succ (add k n0)) (add (succ k) n0)).
484 MApply '(id_repl ? (lslice S k (succ n0) v) (app S (lslice S (succ k) n0 v) (lix S k v))).
485 (MApply 'id_comm; MApply 'lslice_succ_r).
486 MApply '(id_repl ? (lslice S k (succ (succ n0)) v) (app S (lslice S (succ k) (succ n0) v) (lix S k v))).
487 (MApply 'id_comm; MApply 'lslice_succ_r).
488 MApply '(id_trans (List S) (app S (app S (lix S (add (succ k) n0) v) (lslice S (succ k) n0 v)) (lix S k v))).
489 MApply '(id_comp (List S) (List S) [u:?](app S u (lix S k v))).
490 MApply '(H (succ k)).
491 Apply succ_fold. (**)
492 MApply '(id_repl N (succ (add k n0)) (add (succ k) n0)).
497 Theorem lslice_add: (S:Set; v:(List S); k,m,n:N) (Id (List S) (lslice S k (add m n) v) (app S (lslice S (add k m) n v) (lslice S k m v))).
500 MApply '(id_repl ? (lslice S (add k m) zero v) (empty S)).
501 (MApply 'id_comm; MApply 'app_empty).
502 MApply '(id_trans ? (app S (lix S (add k (add m n0)) v) (lslice S k (add m n0) v))).
503 Apply succ_fold. (**)
504 MApply 'lslice_succ_l.
505 MApply '(id_repl ? (lslice S (add k m) (succ n0) v) (app S (lix S (add (add k m) n0) v) (lslice S (add k m) n0 v))).
506 (MApply 'id_comm; MApply 'lslice_succ_l).
507 MApply '(id_trans ? (app S (lix S (add (add k m) n0) v) (app S (lslice S (add k m) n0 v) (lslice S k m v)))).
508 MApply '(id_repl ? (add k (add m n0)) (add (add k m) n0)).
510 MApply '(id_comp (List S) (List S) [w](app S (lix S (add (add k m) n0) v) w)).
511 (MApply 'id_comm; MApply 'app_ass).
514 Theorem lslice_bsadd: (S:Set; v:(List S); k:N; ms:NS; n:N) (Id (List S) (lslice S k (bs_add ms n) v) (bs_app S [m](lslice S (add k (bs_add ms m)) (ms m) v) n)).
516 (MElim 'n 'natrec; Fold (add (ms n0) (bs_add ms n0))).
517 MApply '(id_repl ? (bs_app S [m:N](lslice S (add k (bs_add ms m)) (ms m) v) n0) (lslice S k (bs_add ms n0) v)).
518 MApply '(id_repl ? (add (ms n0) (bs_add ms n0)) (add (bs_add ms n0) (ms n0))).
523 Theorem lslice_rbsadd: (S:Set; v:(List S); k:N; ms:NS; n:N) (Id (List S) (lslice S k (rbs_add ms n) v) (rbs_app S [m](lslice S (add k (bs_add ms m)) (ms m) v) n)).
525 Unfold rbs_add rbs_app rbs_iter.
528 Apply bs_add_fold. (**)
529 MApply 'lslice_bsadd.
532 End arithmetics_results.