]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/lib/streams.ma
precommit for rtmap ...
[helm.git] / matita / matita / contribs / lambdadelta / ground_2 / lib / streams.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground_2/notation/constructors/cons_2.ma".
16 include "ground_2/notation/relations/exteq_3.ma".
17 include "ground_2/lib/star.ma".
18
19 (* STREAMS ******************************************************************)
20
21 coinductive stream (A:Type[0]): Type[0] ≝
22 | seq: A → stream A → stream A
23 .
24
25 interpretation "cons (nstream)" 'Cons b t = (seq ? b t).
26
27 coinductive eq_stream (A): relation (stream A) ≝
28 | eq_seq: ∀t1,t2,b1,b2. b1 = b2 → eq_stream A t1 t2 → eq_stream A (b1@t1) (b2@t2)
29 .
30
31 interpretation "extensional equivalence (nstream)"
32    'ExtEq A t1 t2 = (eq_stream A t1 t2).
33
34 definition eq_stream_repl (A) (R:relation …) ≝
35                           ∀t1,t2. t1 ≐⦋A⦌ t2 → R t1 t2.
36
37 definition eq_stream_repl_back (A) (R:predicate …) ≝
38                                ∀t1. R t1 → ∀t2. t1 ≐⦋A⦌ t2 → R t2.
39
40 definition eq_stream_repl_fwd (A) (R:predicate …) ≝
41                               ∀t1. R t1 → ∀t2. t2 ≐⦋A⦌ t1 → R t2.
42
43 (* Basic inversion lemmas ***************************************************)
44
45 lemma eq_stream_inv_seq: ∀A,t1,t2. t1 ≐⦋A⦌ t2 →
46                          ∀u1,u2,a1,a2. a1@u1 = t1 → a2@u2 = t2 →
47                          u1 ≐ u2 ∧ a1 = a2.
48 #A #t1 #t2 * -t1 -t2
49 #t1 #t2 #b1 #b2 #Hb #Ht #u1 #u2 #a1 #a2 #H1 #H2 destruct /2 width=1 by conj/
50 qed-.
51
52 (* Basic properties *********************************************************)
53
54 lemma stream_rew (A) (t:stream A): match t with [ seq a u ⇒ a @ u ] = t.
55 #A * //
56 qed.
57
58 let corec eq_stream_refl: ∀A. reflexive … (eq_stream A) ≝ ?.
59 #A * #b #t @eq_seq //
60 qed.
61
62 let corec eq_stream_sym: ∀A. symmetric … (eq_stream A) ≝ ?.
63 #A #t1 #t2 * -t1 -t2
64 #t1 #t2 #b1 #b2 #Hb #Ht @eq_seq /2 width=1 by/
65 qed-.
66
67 lemma eq_stream_repl_sym: ∀A,R. eq_stream_repl_back A R → eq_stream_repl_fwd A R.
68 /3 width=3 by eq_stream_sym/ qed-.
69
70 (* Main properties **********************************************************)
71
72 let corec eq_stream_trans: ∀A. Transitive … (eq_stream A) ≝ ?.
73 #A #t1 #t * -t1 -t
74 #t1 #t #b1 #b * #Ht1 * #b2 #t2 #H cases (eq_stream_inv_seq A … H) -H -b
75 /3 width=7 by eq_seq/
76 qed-.
77
78 theorem eq_stream_canc_sn: ∀A,t,t1,t2. t ≐ t1 → t ≐ t2 → t1 ≐⦋A⦌ t2.
79 /3 width=3 by eq_stream_trans, eq_stream_sym/ qed-.
80
81 theorem eq_stream_canc_dx: ∀A,t,t1,t2. t1 ≐ t → t2 ≐ t → t1 ≐⦋A⦌ t2.
82 /3 width=3 by eq_stream_trans, eq_stream_sym/ qed-.